# include using namespace std; struct word { string w; int id; }; word p[10005]; string s[10005]; const int N=1000,M=1000; char matrix[N][M]; stack ans[10005]; int x[10005],y[10005]; mt19937 Rand_Gen(159865487); int T; bool star=false; bool dfs(int t, int x, int y, int v) { // cout<0&&(matrix[x-1][y]==ch||matrix[x-1][y]=='*'))if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&(matrix[x][y-1]==ch||matrix[x][y-1]=='*'))if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y0&&matrix[x-1][y]==ch)if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y0&&matrix[x][y-1]==ch)if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} } if(d==2) { if(y>0&&matrix[x][y-1]==ch)if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y0&&matrix[x-1][y]==ch)if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&matrix[x][y-1]==ch)if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(x>0&&matrix[x-1][y]==ch)if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&matrix[x][y-1]==ch)if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(x>0&&matrix[x-1][y]==ch)if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y0&&matrix[x-1][y]==ch)if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y>0&&matrix[x][y-1]==ch)if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(d==1&&x0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(d==3&&y0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} } if(d==2) { if(y>0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(x>0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(x0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(x>0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y0&&matrix[x-1][y]=='#')if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;} if(y>0&&matrix[x][y-1]=='#')if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;} if(y4*s[t].size()) { char prev; star = 1; if(x>0){prev = matrix[x-1][y];matrix[x-1][y]='*';if(dfs(t,x-1,y,v+1)){ans[t].push('L');return true;}} matrix[x-1][y] = prev; if(y>0){prev = matrix[x][y-1];matrix[x][y-1]='*';if(dfs(t,x,y-1,v+1)){ans[t].push('U');return true;}} matrix[x][y-1] = prev; if(x>T; cin>>n; int l=0,k; for(i=1;i<=n;i++) { cin>>p[i].w; p[i].id=i; } sort(p+1,p+1+n,cmp); for(i=0;i