#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; #define FOR(k,a,b) for(int k(a); k < (b); ++k) #define FORD(k,a,b) for(int k(b-1); k >= (a); --k) #define REP(k,a) for(int k=0; k < (a); ++k) #define ABS(a) ((a)>0?(a):-(a)) char c[1002][1002]; char ans[2000000]; int N,T; char dirc[4]={'U','D','R','L'}; int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}}; string findroute(const pair& from, const pair& to) { vector, string> > q; q.push_back(make_pair(from,string())); REP(i,q.size()) { pair actpos = q[i].first; string actstr = q[i].second; int row = actpos.first; int col = actpos.second; REP(j,4) { int nr = row + dir[j][0]; int nc = col + dir[j][1]; if(nr>=0 && nr=0 && nc npos = make_pair(nr,nc); string ns = actstr + dirc[j]; if(npos == to) return ns; q.push_back(make_pair(npos,ns)); } } } return string(); } int main( int argc, char* argv[] ) { #ifdef HOME freopen("in.txt","r",stdin); freopen("out.txt","wb",stdout); #endif scanf("%d",&T); while(T--) { scanf("%d",&N); REP(i,N) scanf("%s",c[i]); vector dr((N+1)/2); vector > start((N+1)/2), finish((N+1)/2); REP(r, (N+1)/2) { vector > used(2,vector (N,0)); int row1=2*r; int row2=2*r+1; if(row2==N) { row2-=2; swap(row1,row2); } int row = row1; int col = 0; if(c[row][col]=='#') ++row; start[r]=make_pair(row,col); used[row-row1][col]=1; while(1) { int otherrow = row == row1? row2 : row1; //try to step up,down if it is not used or forbidden if(c[otherrow][col]=='.' && !used[otherrow-row1][col]) { //then step if(row==row1) { dr[r].push_back('D'); ++row; } else { dr[r].push_back('U'); --row; } used[row-row1][col]=1; } else if(col+1