#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define mogaAc ios_base::sync_with_stdio(false);
int arr[1005][1005];
bool visited[1005][1005];
int n, m;
void bfs(int i, int j)
{
    queue<pair<string, pair<ll, pair<ll, ll>>>> urutan;
    string cadangan = "";
    urutan.push({cadangan, {0, {i, j}}});
    while (!urutan.empty())
    {
        ll letaki = urutan.front().second.second.first;
        ll letakj = urutan.front().second.second.second;
        ll jarak = urutan.front().second.first;
        string path = urutan.front().first;
        visited[letaki][letakj] = true;

        if (arr[letaki][letakj] == 2)
        {
            cout << "YES" << endl;
            cout << jarak << endl;
            cout << path << endl;
            exit(0);
        }
        urutan.pop();
        if (letaki + 1 < n && arr[letaki + 1][letakj] > 0 && !visited[letaki + 1][letakj])
        {
            string pathN = path + "D";
            urutan.push({pathN, {jarak + 1, {letaki + 1, letakj}}});
        }
        if (letaki - 1 >= 0 && arr[letaki - 1][letakj] > 0 && !visited[letaki - 1][letakj])
        {
            string pathN = path + "U";
            urutan.push({pathN, {jarak + 1, {letaki - 1, letakj}}});
        }
        if (letakj + 1 < m && arr[letaki][letakj + 1] > 0 && !visited[letaki][letakj + 1])
        {
            string pathN = path + "R";
            urutan.push({pathN, {jarak + 1, {letaki, letakj + 1}}});
        }
        if (letakj - 1 >= 0 && arr[letaki][letakj - 1] > 0 && !visited[letaki][letakj - 1])
        {
            string pathN = path + "L";
            urutan.push({pathN, {jarak + 1, {letaki, letakj - 1}}});
        }
    }
    cout << "NO" << endl;
    exit(0);
}

int main()
{
    mogaAc;
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> m;

    int Awali = 0;
    int Awalj = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            char a;
            cin >> a;
            if (a == '.')
            {
                arr[i][j] = 1;
            }
            if (a == 'A')
            {
                arr[i][j] = 1;
                Awali = i;
                Awalj = j;
            }
            if (a == 'B')
            {
                arr[i][j] = 2;
            }
        }
    }
    bfs(Awali, Awalj);
    return 0;
}
// int main()
// {
//     vector<int> a;
//     a.pb(4);
//     a.pb(5);
//     a.pb(8);
//     a.pb(7);
//     vector<int> b;
//     b = a;
//     for (int i = 0; i < b.size(); i++)
//     {
//         cout << b[i] << endl;
//     }
// }

// arrayy------------------------------------------------------
//  buat ngecek array 1 apakah sama dengan array 2:
//   bool sama = equal(arr, arr + size, arr1);
//   buat ngecek besar dari array:
//   int size = sizeof(arr) / sizeof(arr[0]);
// indexke LowerBound/upperbound
// auto it = upper_bound(arr.begin(), arr.end(), x);
// int index = distance(arr.begin(), it);
// cara cepet buat sorting-------------------------------------
// dari kecil ke besar : sort(arr.begin(), arr.end());
// dari besar ke kecil : sort(arr.begin(), arr.end(), greater<int>());
// logaritma
// anggap a=base, b=yang ingin di log, seperti logA (B)
// rumus : log(b)/log(a)
// Statitiska
// menghitung rata rata data tambahan baru
// R0 * (S0/S1) + (Data baru)/S1
// R = Rata rata
// S = Banyak data
// 0 = yang lama
// 1 = yang baru
// ArrayGACORBINSERT (KALAU ELEMENTNYA CUMA 1)
// set atau map