#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define str string
#define pb push_back
#define vc vector
#define ci cin
#define co cout
ll vis[1010][1010],n,m,dp[1010][1010];
string s[1010];
// remove fropen in online judge
void dfs(ll i,ll j,ll len)
{
if(i-1>=0&&s[i-1][j]!='#'&&dp[i-1][j]>len)
{
dp[i-1][j]=min(dp[i-1][j],len);
dfs(i-1,j,len+1);
}
if(j-1>=0&&s[i][j-1]!='#'&&dp[i][j-1]>len)
{
dp[i][j-1]=min(dp[i][j-1],len);
dfs(i,j-1,len+1);
}
if(i+1<n&&s[i+1][j]!='#'&&dp[i+1][j]>len)
{
dp[i+1][j]=min(dp[i+1][j],len);
dfs(i+1,j,len+1);
}
if(j+1<m&&s[i][j+1]!='#'&&dp[i][j+1]>len)
{
dp[i][j+1]=len;
dfs(i,j+1,len+1);
}
// return dp[i][j];
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
freopen("error.txt","w",stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>s[i];
ll ct=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{dp[i][j]=INT_MAX;
vis[i][j]=false;
}
}
ll bi,bj;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(s[i][j]=='A')
{ dp[i][j]=0;
dfs(i,j,1);
}
if(s[i][j]=='B')
{
bi=i;
bj=j; }
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
cout<<dp[i][j]<<" ";
cout<<"\n";
}
if(dp[bi][bj]==INT_MAX)
cout<<"NO";
else
{
cout<<"YES\n"<<dp[bi][bj]<<"\n";
ll i=bi,j=bj;
str st;
while(s[i][j]!='A')
{
if(i-1>=0&&dp[i-1][j]==dp[i][j]-1)
{
st+='D';
i--;
}
else if(j-1>=0&&dp[i][j-1]==dp[i][j]-1)
{
st+='R';
j--;
}
else if(i+1<n&&dp[i+1][j]==dp[i][j]-1)
{
st+='U';
i++;
}
else if(j+1<m&&dp[i][j+1]==dp[i][j]-1)
{
st+='L';
j++;
}
}
for(int i=st.size()-1;i>=0;i--)
cout<<st[i];
}
}
CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbGwgbG9uZyBsb25nIGludCAKI2RlZmluZSBzdHIgc3RyaW5nCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgdmMgdmVjdG9yCiNkZWZpbmUgY2kgY2luCiNkZWZpbmUgY28gY291dApsbCB2aXNbMTAxMF1bMTAxMF0sbixtLGRwWzEwMTBdWzEwMTBdOwpzdHJpbmcgc1sxMDEwXTsKLy8gcmVtb3ZlIGZyb3BlbiBpbiBvbmxpbmUganVkZ2UKdm9pZCBkZnMobGwgaSxsbCBqLGxsIGxlbikKeyAgICAgCiAgICAgCiAgICAgaWYoaS0xPj0wJiZzW2ktMV1bal0hPScjJyYmZHBbaS0xXVtqXT5sZW4pCiAgICAgewogICAgICAgIGRwW2ktMV1bal09bWluKGRwW2ktMV1bal0sbGVuKTsKICAgICAgICAgIGRmcyhpLTEsaixsZW4rMSk7CiAgICAgfQogICAgIGlmKGotMT49MCYmc1tpXVtqLTFdIT0nIycmJmRwW2ldW2otMV0+bGVuKQogICAgIHsKICAgICAgICBkcFtpXVtqLTFdPW1pbihkcFtpXVtqLTFdLGxlbik7CiAgICAgICAgZGZzKGksai0xLGxlbisxKTsKICAgICB9CiAgICAgIGlmKGkrMTxuJiZzW2krMV1bal0hPScjJyYmZHBbaSsxXVtqXT5sZW4pCiAgICAgIHsKICAgICAgICBkcFtpKzFdW2pdPW1pbihkcFtpKzFdW2pdLGxlbik7CiAgICAgICAgZGZzKGkrMSxqLGxlbisxKTsKICAgICAgfQogICAgICAgaWYoaisxPG0mJnNbaV1baisxXSE9JyMnJiZkcFtpXVtqKzFdPmxlbikKICAgICAgewogICAgICAgIGRwW2ldW2orMV09bGVuOwogICAgICAgIGRmcyhpLGorMSxsZW4rMSk7CiAgICAgIH0KICAgICAgLy8gIHJldHVybiBkcFtpXVtqXTsKCn0KaW50IG1haW4oKQp7IAogICAgICNpZm5kZWYgT05MSU5FX0pVREdFIAogICAgIGZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKTsKICAgICBmcmVvcGVuKCJvdXRwdXQudHh0IiwidyIsc3Rkb3V0KTsKICAgICBmcmVvcGVuKCJlcnJvci50eHQiLCJ3IixzdGRlcnIpOwogICAgI2VuZGlmIAoKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIGNpbj4+bj4+bTsKICAKIAogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICBjaW4+PnNbaV07CiAgICBsbCBjdD0wOwogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgIHsKICAgICAgICBmb3IoaW50IGo9MDtqPG07aisrKQogICAgICAgIHtkcFtpXVtqXT1JTlRfTUFYOwogICAgICAgICAgICB2aXNbaV1bal09ZmFsc2U7CiAgICAgICAgfQogICAgfQogICAgbGwgYmksYmo7CiAgICBmb3IoaW50IGk9MDtpPG47aSsrKQogICAgewogICAgICAgIGZvcihpbnQgaj0wO2o8bTtqKyspCiAgICAgICAgewogICAgICAgICAgICBpZihzW2ldW2pdPT0nQScpCiAgICAgICAgICAgIHsgICBkcFtpXVtqXT0wOwogICAgICAgICAgICAgICBkZnMoaSxqLDEpOwogICAgICAgICAgICB9ICAKICAgICAgICAgICAgaWYoc1tpXVtqXT09J0InKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBiaT1pOwogICAgICAgICAgICAgICAgYmo9ajsgICAgICAgICAgICB9CiAgICAgICAgICAgCiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgIHsKICAgICBmb3IoaW50IGo9MDtqPG07aisrKQogICAgIGNvdXQ8PGRwW2ldW2pdPDwiICI7CiAgICAgY291dDw8IlxuIjsKICAgIH0KICAgIGlmKGRwW2JpXVtial09PUlOVF9NQVgpCiAgICAgICAgY291dDw8Ik5PIjsKICAgIGVsc2UKICAgIHsKICAgICAgICBjb3V0PDwiWUVTXG4iPDxkcFtiaV1bYmpdPDwiXG4iOwogICAgICAgIGxsIGk9Ymksaj1iajsKICAgICAgICBzdHIgc3Q7CiAgICAgICAgd2hpbGUoc1tpXVtqXSE9J0EnKQogICAgICAgIHsKICAgICAgICAgICAgaWYoaS0xPj0wJiZkcFtpLTFdW2pdPT1kcFtpXVtqXS0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzdCs9J0QnOwogICAgICAgICAgICAgICAgaS0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoai0xPj0wJiZkcFtpXVtqLTFdPT1kcFtpXVtqXS0xKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBzdCs9J1InOwogICAgICAgICAgICAgICAgai0tOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UgaWYoaSsxPG4mJmRwW2krMV1bal09PWRwW2ldW2pdLTEpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHN0Kz0nVSc7CiAgICAgICAgICAgICAgICBpKys7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSBpZihqKzE8bSYmZHBbaV1baisxXT09ZHBbaV1bal0tMSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgc3QrPSdMJzsKICAgICAgICAgICAgICAgIGorKzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBmb3IoaW50IGk9c3Quc2l6ZSgpLTE7aT49MDtpLS0pCiAgICAgICAgY291dDw8c3RbaV07CiAgICB9CiAgICAKfQo=