#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1005;
struct node
{
int x,y;
int step;
};
node c[maxn][maxn];
char a[maxn][maxn];
int vis[maxn][maxn];
int n;
int m;
char path[maxn][maxn];
int cnt=0;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
bool check(int ax,int ay)
{
if(ax<1)
{
return true;
}
if(ax>n)
{
return true;
}
if(ay<1)
{
return true;
}
if(ay>m)
{
return true;
}
if(vis[ax][ay]==true)
{
return true;
}
return false;
}
int bfs(int posx,int posy,int yyy1,int yyy2)
{
queue<node>q;
vis[posx][posy]=true;
q.push({posx,posy,0});
while(q.empty()==false)
{
node t=q.front();
if(t.x==yyy1&&t.y==yyy2)
{
return t.step;
}
q.pop();
for(int i=0;i<4;i++)
{
int nx=dx[i]+t.x;
int ny=dy[i]+t.y;
if(check(nx,ny))
{
continue;
}
if(a[t.x][t.y]==a[nx][ny])
{
continue;
}
vis[nx][ny]=true;
q.push({nx,ny,t.step+1});
if(t.x-1==nx&&t.y==ny)
{
path[nx][ny]='U';
}
if(t.x+1==nx&&t.y==ny)
{
path[nx][ny]='D';
}
if(t.x==nx&&t.y-1==ny)
{
path[nx][ny]='L';
}
if(t.x==nx&&t.y+1==ny)
{
path[nx][ny]='R';
}
c[nx][ny]={t.x,t.y};
}
}
return -1;
}
void work()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
vis[i][j]=false;
c[i][j]={0,0};
path[i][j]=' ';
}
}
int qx;
int qy;
int zx;
int zy;
qx=1;
qy=1;
zx=n;
zy=m;
int ans=bfs(qx,qy,zx,zy);
if(ans==-1)
{
cout<<ans;
cout<<"\n";
return ;
}
else
{
cout<<ans;
cout<<"\n";
vector<node>ans;
int x=n;
int y=m;
while(true)
{
ans.push_back({x,y});
int px=c[x][y].x;
int py=c[x][y].y;
x=px;
y=py;
if(x==0)
{
break;
}
if(y==0)
{
break;
}
}
for(int i=0;i<ans.size();i++)
{
int px=ans[i].x;
int py=ans[i].y;
cout<<path[px][py];
}
cout<<"\n";
return ;
}
}
signed main()
{
int t;
cin>>t;
while(t--)
{
work();
}
return 0;
}