#include<bits/stdc++.h>
using namespace std;
const int MAX = 5001;
char path[MAX][MAX];
vector<vector<int> > valid(MAX,vector<int>(MAX,0));
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
string moves[] = {"L","R","U","D"};
int n,m;
bool is_sol(pair<int,int> point){
return point.first == 0 || point.first == n-1
|| point.second == 0 || point.second == m-1;
}
bool check(pair<int,int> p){
if(p.first<0 || p.second<0 || !valid[p.first][p.second] ||
p.first>=n || p.second>=m || path[p.first][p.second]!='.') return false;
return true;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
queue<pair<int,int> > pq_; //this is for monsters..
queue<pair<pair<int,int>,string> > pq; // this is for the player...
cin>>n>>m;
for(int i = 0;i<n;i++)
for(int j = 0;j<m;j++){
cin>>path[i][j];
if(path[i][j]=='.') valid[i][j] = 1;
else if(path[i][j] == 'A') pq.push({{i,j},""});
else if(path[i][j] == 'M') pq_.push({i,j});
}
while(!pq.empty()){
pair<int,int> p = pq_.front();
pq_.pop();
for(int i = 0;i<4;i++){
int xx_ = p.first + dx[i];
int yy_ = p.second + dy[i];
if(check(make_pair(xx_,yy_)))
{
pq_.push({xx_,yy_}); valid[xx_][yy_] = 0;
}
}
pair<pair<int,int>,string> q = pq.front();
pq.pop();
string s = q.second;
if(is_sol({q.first.first,q.first.second})){
cout<<"YES"<<'\n'<<s.length()<<'\n';
cout<<s<<'\n';
return 0;
}
for(int i = 0;i<4;i++){
int xx_ = q.first.first + dx[i];
int yy_ = q.first.second + dy[i];
if(check(make_pair(xx_,yy_)))
{
pq.push({{xx_,yy_},s + moves[i]}); valid[xx_][yy_] = 0;
}
}
}
cout<<"NO"<<'\n';
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKY29uc3QgaW50IE1BWCA9IDUwMDE7CmNoYXIgcGF0aFtNQVhdW01BWF07CnZlY3Rvcjx2ZWN0b3I8aW50PiA+IHZhbGlkKE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