// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
cout << T << "\n";
for(int t =0; t < T; t++) {
string s;
cin >> s;
vector< vector<bool> > isF(242,vector<bool>(142,false));
int y =109, x =0, d =0;
isF[y][x] =true;
int dx[] ={1,0,-1,0};
int dy[] ={0,1,0,-1};
for(int i =0; i < s.length(); i++) {
if(s[i] == 'R') {
d =(d+1)%4;
isF[y+dy[d]][x+dx[d]] =true;
x +=dx[d];
y +=dy[d];
continue;}
if(s[i] == 'F') {
isF[y+dy[d]][x+dx[d]] =true;
x +=dx[d];
y +=dy[d];
continue;}
if(s[i] == 'L') {
d =(d+3)%4;
isF[y+dy[d]][x+dx[d]] =true;
x +=dx[d];
y +=dy[d];
continue;}
x -=dx[d];
y -=dy[d];
d =(d+2)%4;}
x =0;
while(x < 242-9) {
bool b =false;
for(int i =0; i < 142; i++) if(isF[x+1][i]) b =true;
if(!b) x++;
else break;}
int x2 =241;
while(x2 > 0) {
bool b =false;
for(int i =0; i < 142; i++) if(isF[x2-1][i]) b =true;
if(!b) x2--;
else break;}
y =0;
for(int i =0; i < 242; i++) for(int j =0; j < 142; j++)
if(isF[i][j]) y =max(y,j);
cout << x2-x+1 << " " << y+2 << "\n";
for(int i =0; i < x2-x+1; i++) {
string s;
for(int j =0; j <= y+1; j++) {
if(isF[i+x][j]) s +='.';
else s +='#';}
cout << s << "\n";}
}
return 0;}
// look at my code
// my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