10 10
.L.....R..
.........U
..D....D..
.R......L.
....L.....
.........D
......U...
D....R....
...U......
........L.
 5 5
DD..D
.....
LU...
U...U
.UL.U
 1 1
U
 5 5
UD..L
RRD..
..RDD
UUL..
DDLRR
 19 23
U..U..R........L...D...
.D.....UL.U.U........DR
..D.U..D....L......R...
D.......RL.L....D.....R
U..D.....U...U.L..D...U
...........L...........
U....U....D.U......LRR.
......RL...U...L.......
DLU..U......UU.U.U.D...
...........D....U......
U...DL......LL.....R...
...U..DD..........LD...
.R.........D.....UU...U
....D......R..........D
.L..........R.....L....
.R........L.LL....R....
..R...D........R....D..
.LR.R..LDU.DDRL......U.
...LL.....D.....DD.....
 11 29
URRUUDDLURLRDDLLRLDUDR.UDLLD.
LRRUDLUDLDULUDL.DURDRR.RRLLRR
D.DUDDURLRDDULDUDDUDDURRDLD.L
.RULURURRDLRRRLUUUU.RDLDLRRRL
.RLDDU.UUULUURURRLLUU.RLDRDUD
LRL.URRRDDURUURUDRRDLDDULRDRL
RLULDU.LRDUDRLDLRDDDDRUUDRDLL
DLUDURRDDUDLLDLLUURLDRUURRLUL
L.RRURRDDRRURRRDDUDRRDULR.LUR
LDLRULURRUULRDUUULLU.LLU.LLLL
DUURDULDDUDLRUUDRUULURLD.RL.U
 2 2
RD
UL
 1 10
LLLLLRRRRR
 3 3
...
...
..R
 17 13
...LD.UR.RUU.
LDLULDUDRRDRL
DD.RRLRUR.UD.
RU...D...LD..
.UR.R...URUUD
.RURD.RLR.D.R
.UUU.RU...UR.
UUUU.R.......
RL.LRU.UD.DUD
LD.DRURRLRDRL
.DR..UULUDDR.
LRLURRUUDDLUR
.LRDDLLR.L.DU
DRUDLLD.LRRU.
..DL.UDL.DUL.
U.DL..D..U.RD
RR.R...RL.L..

2 2
 4 1
 1 1
 8 3
 9 1
 94 1
 4 4
 5 2
 1 1
 24 2


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <bitset>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <climits>




using namespace std;
#define REP(i,n) for(int i = 0; i < int(n); ++i)
#define REPV(i, n) for (int i = (n) - 1; (int)i >= 0; --i)
#define FOR(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define FORV(i, a, b) for(int i = (int)(a)-1; i >= (int)(b); --i)
#define FORE(i, a) for(int i = 0; i < (int)a.size(); ++i)


#define two(x) (1LL << (x))
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()


#define sz(a) (int)a.size()
#define shows(a) if(a++)cout<<endl
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x, y)
#define println(a) cout<<a<<endl
#define print(a) cout<<a
#define clr(a,b) memset(a,b,sizeof(a))
#define OO 1e8
#define EPS 1e-6
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<vd> vvd;
typedef vector<vector<int> > vvi;
typedef vector<pii> vpi;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<ull> vull;


template<class T> void checkmin(T &a, T b){if (b<a)a=b;}
template<class T> void checkmax(T &a, T b){if (b>a)a=b;}
template<class T> void out(T t[], int n){REP(i, n)cout<<t[i]<<" "; cout<<endl;}
template<class T> void out(vector<T> t, int n=-1){for (int i=0; i<(n==-1?t.size():n); ++i) cout<<t[i]<<" "; cout<<endl;}
inline int count_bit(int n){return (n==0)?0:1+count_bit(n&(n-1));}
inline int low_bit(int n){return (n^n-1)&n;}
inline int ctz(int n){return (n==0?0:ctz(n>>1)+1);}
int toInt(string s){int a; istringstream(s)>>a; return a;}
string toStr(int a){ostringstream os; os<<a; return os.str();}
string reverse(string& s){ int n=s.size();REP(i,n/2) s[i]=s[n-1-i];return s;}
inline int isvalid(int i,int j,int H,int L){ return (i>=H||i<0||j>=L||j<0)? 0:1;}
inline int doubleComare(double x,double y){if(fabs(x-y)<=EPS) return 0; if(x<y) return -1; return 1;}
/*
int main() // ACCEPTED
{

    int n,d,m;
    cin>>n>>d;
    vi tab(n);
    REP(i,n) cin>>tab[i];
    sort(ALL(tab));
    cin>>m;
    int r=min(n,m);
    int s=0;
    for(int i=0;i<r;i++)
        s+=tab[i];
    if(m>n) s-=d*(m-n);
    cout<<s<<endl;
    return 0;
}*/
/*
int main()
{
    int n,m,r;
    scanf("%d %d",&n,&m);
    //cin>>n>>m;
    vi tab(n);
    REP(i,n) scanf("%d",&tab[i]);
    sort(ALL(tab));
    REP(i,m) {
        scanf("%d",&r);
        int s=1,t=tab[r-1];
        for(int j=r;j<n;j++)
            if(tab[j]!=t) {t=tab[j];s++;}
        printf("%d\n",s);
    }
    return 0;
}*/
/*
int main()
{
    ll w,m,k,r=0;
    cin>>w>>m>>k;
    int t=1+(int)log10((double)m);
    while(w>0){
        ll b=pow(10.0,t)-m;
        if((w/t)/k>=b) r+=b;
        else { r+=w/t/k; break;}
        w-=b*t*k;
        m=pow(10.0,t);t++;
    }
    cout<<r<<endl;
    return 0;
}*/
/*
int main()
{
    int t[10]={0};
    char r;
    int n;
    cin>>n;
    REP(i,16){ cin>>r; if(isdigit(r))t[r-'0']++;}
    REP(i,10) if(t[i]>2*n) {cout<<"NO"<<endl; return 0;} 
    cout<<"YES"<<endl;
    return 0;
}*/
/*
int main()//ACCEPTED
{

    string s;
    cin>>s;
    ull md=0,mg=0,si=0;
    FORE(i,s) if(s[i]=='^') si=i;
    FORE(i,s) if(isdigit(s[i])){if(i<si) mg+=(si-i)*(s[i]-'0'); else md+=(i-si)*(s[i]-'0'); }
        if(md==mg) cout<<"balance"<<endl;
        else if(md<mg) cout<<"left"<<endl;
        else cout<<"right"<<endl;
    return 0;
}*/
/*
struct Edge{
    int from,to,w;
    Edge(int from,int to,int w) : from(from),to(to),w(w){}
};
int main()
{
    int n,m;
    cin>>n>>m;
    vector< vector< Edge > > graph(n);
    vi o(m),e(m),w(m);
    REP(i,m){ 
        cin>>o[i]>>e[i]>>w[i];
        graph[o[i]-1].pb(Edge(o[i],e[i],w[i]));
    }
    REP(i,m){

    }
    return 0;
}*/
/*
class point{
    
public:
    int x;
    int y;
     

    int & get_x(){
        return x;
    }
    void set_x(int xx){
        x=xx;
    }
};
int main()
{
    point p;
    p.set_x(100);
    cout<<p.get_x()<<endl;
    p.get_x()=10;
    cout<<p.x<<endl;
    system("pause");
    return 0;
}*//*
int isPrime(ull n) //O(Vn)
{
    if(n==2) return 1;
    if(n<2||n%2==0) return 0;
    for(ll i=3;i*i<=n;i+=2)
        if(n%i==0)
            return 0;
    return 1;
}
int main()
{
    ull n;
    REP(i,8){
        cin>>n;
        if(n==5) n=(ull)pow(2.0,35),n--;
        if(isPrime(n)) cout<<i+1;
        else cout<<0;
    }
    system("pause");
    return 0;
}*/
//******************************************Round 1******************************************************** 
/*int main()//Prob 1
{
    ull n,m,a,x,y;
    cin>>n>>m>>a;
    x=(n%a==0)?n/a:1+n/a;
    y=(m%a==0)?m/a:1+m/a;
    cout<<x*y<<endl;
    return 0;
}*//*
string x;
void solve(ll n){if(!n)return ; solve((n%26==0)?n/26-1:n/26); x.pb((n%26==0)?'Z':n%26+'A'-1);}
int main()//prob 2
{
    int n;
    cin>>n;
    while(n--){
        string s,r;
        ll a=0,b=0;
        int g=0;
        cin>>s;
        istringstream is(s);
        FORE(i,s){
            if(isdigit(s[i])) g=1;
            else if(g) {g=0;break;}
        }
        if(!g){
            x.clear();
            char d; is>>d>>a>>d>>b;
            solve(b);
            cout<<x<<a<<endl;
        }
        else{
            FORE(i,s){
                if(isdigit(s[i])) a=a*10+s[i]-'0';
                else r.pb(s[i]);
            }
            FORE(i,r) b=b*26+r[i]-'A'+1;
            cout<<"R"<<a<<"C"<<b<<endl;
        }
    }
    return 0;
}/*
#define eps 1e-4
#define PI 3.14159265359
double gcd(double x, double y) {
    while (fabs(x) > eps && fabs(y) > eps) {
        if (x > y) x -= floor(x / y) * y;
        else y -= floor(y / x) * x;
    }
    return x + y;
}
int main()//prob 3
{
    //ifstream cin("a.in");
    double s,t,u,v,x,y;
    cin>>s>>t>>u>>v>>x>>y;
    double a=hypot(s-u,t-v),b=hypot(s-x,t-y),c=hypot(x-u,y-v);
    double p=(a+b+c)/2,m=sqrt(p*(p-a)*(p-b)*(p-c)),r=(a*b*c)/(4*m);
    double A=acos((b*b+c*c-a*a)/(2*b*c)),B=acos((-b*b+c*c+a*a)/(2*a*c)),C=acos((b*b-c*c+a*a)/(2*b*a));
    double n=(PI/gcd(C,gcd(A,B)));
    //cout<<r<<" "<<a<<" "<<b<<" "<<c<<" "<<m<<" "<<A<<" "<<B<<" "<<C<<" "<<n<<endl;
    m=n/2*r*r*sin(2*PI/n);
    cout.precision(8);
    cout<<fixed<<m<<endl;
    //system("pause");
    return 0;
}
*/
///******************************************ROUND 2*******************************************
/*
int main()//Prob 1
{
    int n;
    //ifstream cin("a.in");
    cin>>n;
    map<string,ll> a,z;

    vector <pair<string,int> > moves(1001);
    ll ma=-OO;string ms;
    string s;int sc;
    REP(kk,n){
        cin>>s>>sc;
        moves[kk]=mp(s,sc);
        z[s]+=sc;
        ma=-OO;
        for(map<string,ll>::iterator it=z.begin();it!=z.end();++it)
            if(it->nd>ma) ma=it->nd;
    }
    set<string> ss;
    for(map<string,ll>::iterator it=z.begin();it!=z.end();++it)
        if(it->nd==ma) ss.insert(it->st);
    REP(kk,n){
        a[moves[kk].st]+=moves[kk].nd;
        if(ss.find(moves[kk].st)!=ss.end()&&a[moves[kk].st]>=ma) {cout<<moves[kk].st<<endl;break;}
    }
    //system("pause");
    return 0;
}*//*
int n;
int mat[1001][1001];
int x[1001][1001][2]={0};
ll dp[1001][1001][2];
ll solve(int r,int c,int z)
{
    if(!isvalid(r,c,n,n)) return INT_MAX;
    ll &ret=dp[r][c][z];
    if(ret!=-1) return ret;
    if(r==n-1&&c==n-1) return ret=x[r][c][z];
    ret=x[r][c][z]+min(solve(r+1,c,z),solve(r,c+1,z));
    return ret;
}

string path;
void solves(int r,int c,int z)
{
    ll &ret=dp[r][c][z];
    if(r==n-1&&c==n-1) return ;
    ret=x[r][c][z]+min(solve(r+1,c,z),solve(r,c+1,z));
    if(ret==x[r][c][z]+solve(r+1,c,z)){
        path.pb('D');
        solves(r+1,c,z);
        return;
    }
    path.pb('R');
    solves(r,c+1,z);
    return;
}
int a=-1,q;
int main()//prob 2
{
    ifstream cin("a.in");
    cin>>n;
    clr(dp,-1);
    REP(i,n) REP(j,n){ cin>>mat[i][j];x[i][j][0]=x[i][j][1]=0;
        int b=mat[i][j];
        if(b==0){b=10,a=i,q=j;}
        while(b&&b%2==0) x[i][j][0]++,b/=2;
        while(b&&b%5==0) x[i][j][1]++,b/=5;
    }
    ll r2=solve(0,0,0),r5=solve(0,0,1);
    if(r2<=r5){
        if(r2>1&&a!=-1){
            cout<<1<<endl;
            REP(k,a) cout<<'D';
            REP(k,q) cout<<'R';
            REP(k,n-1-a) cout<<'D';
            REP(k,n-1-q) cout<<'R';
            return 0;
        }
        solves(0,0,0);
        cout<<r2<<endl;
    }
    else{
        if(r5>1&&a!=-1){
            cout<<1<<endl;
            REP(k,a) cout<<'D';
            REP(k,q) cout<<'R';
            REP(k,n-1-a) cout<<'D';
            REP(k,n-1-q) cout<<'R';
            return 0;
        }
    solves(0,0,1);
    cout<<r5<<endl;}
    cout<<path<<endl;
    system("pause");
    return 0;
}*//*
double xi,yi,x[3],y[3],r[3],dis[3];
double chk(double a,double b)
{
    double rt=0;
    REP(i,3) dis[i]=sqrt(SQ(x[i]-a)+SQ(y[i]-b));
    REP(i,3) rt+=SQ(dis[i]/r[i] - dis[(i+1)%3]/r[(i+1)%3]);
    return rt;
}
int main()//prob 3
{
    //ifstream cin("a.in");
    REP(i,3) cin>>x[i]>>y[i]>>r[i];
    double ra=1;
    xi=(x[0]+x[1]+x[2])/3,yi=(y[0]+y[1]+y[2])/3;
    while(ra>EPS){
        if(chk(xi,yi)>chk(xi-ra,yi)) xi-=ra;
        else if(chk(xi,yi)>chk(xi+ra,yi)) xi+=ra;
        else if(chk(xi,yi)>chk(xi,yi-ra)) yi-=ra;
        else if(chk(xi,yi)>chk(xi,yi+ra)) yi+=ra;
        else ra*=0.5;
    }
    cout.precision(5);
    if(chk(xi,yi)<EPS) cout<<fixed<<xi<<" "<<yi<<endl;
    //system("pause");
    return 0;
}*/

//****************************************ROUND 3*****************************************************
/*
int main()//prob1
{
    int a,b,x,y,i,j;
    vs v;
    char c;cin>>c>>b;
    a=c-'a';
    cin>>c>>y; x=c-'a';
    i=a,j=b;
    while(i!=x||j!=y){
        string s;
        if(x>i) s.pb('R'),i++; else if(x<i) s.pb('L'),i--;
        if(y>j) s.pb('U'),j++; else if(y<j) s.pb('D'),j--;
        
        v.pb(s);
    }
    cout<<sz(v)<<endl;
    FORE(z,v) cout<<v[z]<<endl;
    //system("pause");
    return 0;
}*//*
int main()
{
    ifstream cin("a.in");
    int n,v,a,b,s1=0,s2=0;
    vector<pii > v1(100002,mp(0,0)),v2(100002,mp(0,0));
    cin>>n>>v;
    REP(i,n) {cin>>a>>b;if(a==1)v1[s1++]=mp(-b,i+1);else v2[s2++]=mp(-b,i+1);}
    sort(v1.begin(),v1.begin()+s1);sort(v2.begin(),v2.begin()+s2);
    int c1=0,c2=0;
    ll ans=0;
    ostringstream out;
    while(v>0&&(c1<s1||c2<s2)){
        //cout<<v<<endl;
        if(v>1){
            if(-v2[c2].st>=-v1[c1].st-v1[c1+1].st) 
                out<<v2[c2].nd<<" ",ans+=v2[c2].st,v-=2,c2++;
            else out<<v1[c1].nd<<((1+c1<s1)?" "+toStr(v1[c1+1].nd):"")<<" ",ans+=v1[c1].st+v1[1+c1].st,v-=(1+c1<s1)?2:1,c1+=(1+c1<s1)?2:1;
        }
        else if(c1<s1)  out<<v1[c1].nd<<" ",ans+=v1[c1].st,v-=1,c1++;
        else break;
    }
    cout<<-ans<<"\n"<<out.str()<<endl;
    system("pause");
    return 0;
}*/
//*********************************************************ROUND 4*************************************************************
/*int r=0,n,w,h;
vector<pair<pii,int> > v;
int dp[5002];
int pre[5002];
int solve(int i)
{
    int &ret = dp[i];
    if(ret!=-1)  return ret;
    ret=1;
    REP(j,n+1){
        if(v[j].st.st>v[i].st.st&&v[j].st.nd>v[i].st.nd){
            if(ret<1+solve(j)){
                ret=1+solve(j);
                pre[i]=v[j].nd;
            }
        }
    }
    return ret;
}
int main()//prob 4
{ 
    ifstream cin("a.in");
    int a,b;
    
    cin>>n;
    v.resize(n+1);
    REP(i,n+1) {
        cin>>v[i].st.st>>v[i].st.nd;
        v[i].nd=i;
    }
    clr(dp,-1);
    clr(pre,-1);
    cout<<solve(0)-1<<endl;
    //out(vi(pre,pre+3));
    for (int i = pre[0]; i != -1; i = pre[i])
        cout<<i<<" ";
    //prin(pre[0]);
    system("pause");
    return 0;
}
/*
int main()//Prob 3
{
    ifstream cin("a.in");
    int n;
    cin>>n;
    string s;
    map<string,int> m;
    REP(i,n) {
        cin>>s;
        if(m.find(s)==m.end()){
            m.insert(mp(s,0));
            cout<<"OK"<<endl;
        }
        else{
            m.insert(mp(s+toStr(++m[s]),0));
            cout<<s<<m[s]<<endl;
        }
    }
    system("pause");
    return 0;
}*/
/*
int main()//prob 2
{
    ifstream cin("a.in");
    int d,st,a=0,smin=0,smax=0;
    
    cin>>d>>st;
    vi sm(d),sx(d);
    REP(i,d) 
        cin>>sm[i]>>sx[i],smin+=sm[i],smax+=sx[i];
        
    
    if(st<smin||st>smax)  cout<<"NO"<<endl;
    else{
        cout<<"YES"<<endl;
        REP(i,d){
            FOR(j,sm[i],sx[i]){
                if(!(st-j<smin-sm[i]||st-j>smax-sx[i])){
                    
                    cout<<j<<" ";
                    st-=j;
                    smin-=sm[i],smax-=sx[i];
                    break;
                }
            }
        }
    }
    system("pause");
    return 0;
}*/
/////////////////////////////////////////////////////////ROUND 5/////////////////////////////////////////////////////////
/*
int main()//prob1
{
    ifstream cin("a.in");
    string r;
    int t=0;
    set<string> s;
    while(getline(cin,r)){
        if(r[0]=='+') s.insert(r.substr(1));
        else if(r[0]=='-') s.erase(r.substr(1));
        else{
            t+=s.size()*(r.size()-r.find(':')-1);
        }
    }
    cout<<t<<endl;
    system("pause");
    return 0;
}*//*
int main()//prob2
{
    ifstream cin("a.in");
    vs v;
    int m=0,s=0,w=1;
    string r;
    while(getline(cin,r)){
        v.pb(r);
        s++;
        if(sz(r)>m) m=sz(r);
    }
    cout<<string(m+2,'*')<<endl;
    REP(i,s){
        if((m-sz(v[i]))%2==0)
            cout<<"*"+string((m-sz(v[i]))/2,' ')+v[i]+string((m-sz(v[i]))/2,' ')+"*"<<endl;
        else if(w) cout<<"*"+string((m-sz(v[i]))/2,' ')+v[i]+string(1+(m-sz(v[i]))/2,' ')+"*"<<endl,w=0;
        else cout<<"*"+string(1+(m-sz(v[i]))/2,' ')+v[i]+string((m-sz(v[i]))/2,' ')+"*"<<endl,w=1;
    }
    cout<<string(m+2,'*')<<endl;
    system("pause");
    return 0;
}*/
/*
int main()//prob3
{
    ifstream cin("a.in");
    ios::sync_with_stdio(false);
    string r;
    cin>>r;
    vi d(sz(r)+1,0), c(sz(r)+1,0);
    int sz = 0, ma = 0;
    stack<int > s;
    FORE(i,r){
        if(r[i]=='(') s.push(i);
        else{
            if(sz(s)) {
                d[i] = s.top();
                s.pop();
                c[i] = i + 1 - d[i];
                if (d[i] - 1 >= 0 && r[d[i] - 1] == ')')
                    c[i] += c[d[i] - 1];
            }
        }
    }
    ma = *max_element(c.begin(), c.begin() + sz(r));
    if (!ma) cout << "0 1" << endl;
    else cout << ma << " " << count(c.begin(), c.begin() + sz(r), ma) << endl;
    system("pause");
    return 0;
}*/
/*
int main()
{
    int d, l, w, v;

    return 0;
}
*//*
int main()
{
    ifstream cin("a.in");
    vs ss(3);
    vi sym(3); sym[0] = 2, sym[1] = 1, sym[2] = 0;
    REP(i, 3) cin >> ss[i];
    int z = 0;
    REP(i, 3) REP(j, 3) if (ss[i][j] == 'X'&&ss[sym[i]][sym[j]] != 'X') z = 1;
    cout << ((z) ? "NO" : "YES") << endl;


    system("pause");
    return 0;
}*/
/*
int main()
{
    string n, m;
    cin >> n >> m;
    sort(ALL(n));
    int j=-1;
    FORE(i, n){
        if (n[i] != '0'){ j = i; break;}
    }
    //cout << n << endl;
    string an;
    if (j != -1){
        an.pb(n[j]);
        FORE(i, n){
            if (i == j){ continue; }
            an.pb(n[i]);

        }
    }
    else{
        an = string(sz(n), '0');
    }
    //cout << an << endl;
    if (m == an) cout << "OK";
    else cout << "WRONG_ANSWER";
    //system("pause");
    return 0;
}
*/
/*
int main()
{
    //ifstream cin("a.in");
    int n, m;
    cin >> n >> m;
    map<string, int> ma;
    string s;
    vi tag(n);
    REP(i, n) cin >> tag[i];
    REP(i, m){
        cin >> s;
        ma[s]++;
    }
    vi tab(ma.size());
    vi bat(ma.size());
    int j = 0;
    for (map<string, int>::iterator it = ma.begin(); it != ma.end(); it++, j++)
        tab[j] = it->second;
    sort(RALL(tab));
    sort(ALL(tag));
    ll mi = 0, mam = 0;
    FORE(i, tab){
        mi += tab[i] * tag[i];
    }
    sort(RALL(tag));
    FORE(i, tab){
        mam += tab[i] * tag[i];
    }

    cout << mi << " " << mam << endl;
    
    //system("pause");
    return 0;
}*/
/*
int main()
{
    int n;
    cin >> n;
    vector<pair<pii, pii > > tab(n);
    REP(i, n){
        cin >>tab[i].st.st>>tab[i].st.second>>tab[i].second.first;
        tab[i].second .nd= i;
    }
    sort(ALL(tab));
    FORE(i, tab) cout << " " << tab[i].second.second;
    int an = 0;
    REP(i, n-1){
        if (tab[i].first.first < tab[n - 1].first.first&&tab[i].first.nd < tab[n - 1].first.nd
            &&tab[i].nd.first < tab[n - 1].nd.first)
            an++;
    }
    cout << an << endl;

    system("pause");
    return 0;
}*/

/*int v[1002][1002];
int main()
{
    

    int n;
    cin >> n;
    REP(i, n) REP(j, n) v[i][j] = (i == j) ? 0 :  (i + j) % (n);
    REP(i, n) FOR(k, 1, n - 1){
        int a = 0;
        REP(j, n) 
        if (v[i][j] == k){ a = 1; break; }
        if (!a)v[i][n - 1] = v[n - 1][i] = k;
    }

    REP(i, n){
        REP(j, n)
            cout << v[i][j] << " ";
        cout << endl;
    }
    system("pause");
    return 0;

    }*//*
int main()
{
    
    //ifstream cin("a.in");
    int r, g, b;
    cin >> r >> g >> b;
    int an = 29,t=0;
    while (r || g || b){
        if (t % 3 == 0 && r) r -= (r >= 2) ? 2 : 1;
        else if (t % 3 == 1 && g) g -= (g >= 2) ? 2 : 1;
        else if (t % 3 == 2&& b) b -= (b >= 2) ? 2 : 1;
        an++, t++;
    }
    cout << an << endl;
    system("pause");
    return 0;

}*/
/*int main()
{

    ifstream cin("a.in");
    int n,m;
    cin >> n >> m;
    vs v(n);
    int vis[101][101];
    clr(vis, 0);
    REP(i, n) cin >> v[i];
    REP(i, n) {
        vector<char> f(128, 0);
        REP(j, m) {
            f[v[i][j]]++;
        }
        REP(j,m){
            if (f[v[i][j]] > 1) vis[i][j] = 1;
        }
    }
    REP(i, m) {
        vector<char> f(128, 0);
        REP(j, n) {
            f[v[j][i]]++;
        }
        REP(j, n){
            if (f[v[j][i]] > 1) vis[j][i] = 1;
        }
    }
    string s;
    REP(i, n) {
        REP(j, m) {
            if (!vis[i][j])
            s.pb(v[i][j]);
        }
    }
    cout << s << endl;
    system("pause");
    return 0;

}*/
int n, m;
char v[5001][5001];
int solve(int r, int c)
{
    if (!isvalid(r, c, n, m)) return 0;
    if (v[r][c] == 'D'){
        int x = r + 1;
        for (; x < n&&v[x][c] == '.'; x++);
        if (isvalid(x, c, n, m)) {
            v[r][c] = '.';
            x = 1 + solve(x, c);
            v[r][c] = 'D';
            return x;
        }
        
    }
    else if (v[r][c] == 'U'){
        int x = r - 1;
        for (; x >= 0&&v[x][c] == '.'; x--);
        if (isvalid(x, c, n, m)) {
            v[r][c] = '.';
            x = 1 + solve(x, c);
            v[r][c] = 'U';
            return x;
        }

    }
    else if (v[r][c] == 'R'){
        int y = c + 1;
        for (; y < m&&v[r][y] == '.'; y++);
        if (isvalid(r, y, n, m)) {
            v[r][c] = '.';
            y = 1 + solve(r, y);
            v[r][c] = 'R';
            return y;
        }
    }
    else {
        int y = c - 1;
        for (; y>=0&&v[r][y] == '.'; y--);
        if (isvalid(r, y, n, m)) {
            v[r][c] = '.';
            y= 1 + solve(r, y);
            v[r][c] = 'L';
            return y;
        }
    }
    return 0;
}
void main()
{
    //ifstream cin("a.in");
    cin >> n >> m;
    REP(i, n) {
        REP(j, m) cin >> v[i][j];
        cin.ignore();
    }
    int ma = 0, c = 0;
    REP(i, n) REP(j, n)if(v[i][j]!='.') {
        int l = 1+solve(i, j);
        if (l > ma)ma = l, c = 1;
        else if (l == ma) c++;
    }
    cout << ma << " " << c << endl;
    //system("pause");
}