#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

struct Node {
    int x, y, dist;
    Node (int ix, int iy, int id) :
         x (ix), y (iy), dist(id) {};
};

vector<string> graph;
vector< vector<Node> > components;

bool comp (Node x, Node y) {
    return x.dist > y.dist;
}

void dfs (int x, int y, int level, vector<Node>& component) {
    int n = graph.size(), m = graph[0].size();
    graph[x][y] = '#';
    component.push_back(Node(x, y, level));
    if (x > 0 && graph[x - 1][y] == '.')
        dfs(x - 1, y, level + 1, component);
    if (x < n - 1 && graph[x + 1][y] == '.')
        dfs(x + 1, y, level + 1, component);
    if (y > 0 && graph[x][y - 1] == '.')
        dfs(x, y - 1, level + 1, component);
    if (y < m - 1 && graph[x][y + 1] == '.')
        dfs(x, y + 1, level + 1, component);
}

int main () {
    int n, m; cin >> n >> m;
    graph.resize(n);
    for (int i = 0; i < n; i++)
        cin >> graph[i];
    long long total = 0;
    vector<string> result;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] != '#') {
                string c1 = "1", c2 = "1";
                c1[0] += i, c2[0] += j;
                result.push_back("B " + c1 + " " + c2);
            }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] == '.') {
                vector<Node> component;
                dfs(i, j, 0, component);
                sort(component.begin(), component.end(), comp);
                components.push_back(component);
            }
     for (int i = 0; i < components.size(); i++)
         for (int j = 0; j < components[i].size() - 1; j++) {
             string c1 = "1", c2 = "1";
             c1[0] += components[i][j].x, c2[0] += components[i][j].y;
             result.push_back("D " + c1 + " " + c2);
             result.push_back("R " + c1 + " " + c2);
         }
     if (result.size())
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	string block[n+5];
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}

	vector<pair<char, pair<int, int> > > sol;
	vector<pair<int, pair<int, int> > > b;

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == '.') {
				sol.pb(mp('B', mp(i+1, j+1)));
				block[i][j] = 'B';
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == 'B') {
				int nh = 0;
				if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
				if (i+1 < n && block[i+1][j] == 'B') nh++;
				if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
				if (j+1 < m && block[i][j+1] == 'B') nh++;
				b.pb(mp(nh, mp(i, j)));

			}
		}
	}

	vsort(b);

	rep(k, sz(b)) {
		int i = b[k].se.fi;
		int j = b[k].se.se;

		int nh = 0;

		if (block[i][j] == 'R') continue;

		if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
		if (i+1 < m && block[i+1][j] == 'B') nh++;
		if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
		if (j+1 < n && block[i][j+1] == 'B') nh++;

		if (nh > 0) {
			sol.pb(mp('D', mp(i+1, j+1)));
			sol.pb(mp('R', mp(i+1, j+1)));
			block[i][j] = 'R';
		}
	}

	printf("%d\n", sz(sol));

	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi, sol[i].se.se);
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	string block[n+5];
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}

	vector<pair<char, pair<int, int> > > sol;
	vector<pair<int, pair<int, int> > > b;

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == '.') {
				sol.pb(mp('B', mp(i+1, j+1)));
				block[i][j] = 'B';
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == 'B') {
				int nh = 0;
				if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
				if (i+1 < m && block[i+1][j] == 'B') nh++;
				if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
				if (j+1 < n && block[i][j+1] == 'B') nh++;
				b.pb(mp(nh, mp(i, j)));
			}
		}
	}

	vsort(b);

	ford(k, sz(b) - 1, 0) {
		int i = b[k].se.fi;
		int j = b[k].se.se;
		if (block[i][j] == 'R') continue;
		if (i-1 >= 0 && block[i-1][j] == 'B') {
			block[i-1][j] = 'R';
			sol.pb(mp('D', mp(i-1+1, j+1)));
			sol.pb(mp('R', mp(i-1+1, j+1)));
		}
		if (i+1 < m && block[i+1][j] == 'B') {
			block[i+1][j] = 'R';
			sol.pb(mp('D', mp(i+1+1, j+1)));
			sol.pb(mp('R', mp(i+1+1, j+1)));
		}
		if (j-1 >= 0 && block[i][j-1] == 'B') {
			block[i][j-1] = 'R';
			sol.pb(mp('D', mp(i+1, j-1+1)));
			sol.pb(mp('R', mp(i+1+1, j+1)));
		}
		if (j+1 < n && block[i][j+1] == 'B') {
			block[i][j+1] = 'R';
			sol.pb(mp('D', mp(i+1, j+1+1)));
			sol.pb(mp('R', mp(i+1+1, j+1)));
		}
	}

	printf("%d\n", sz(sol));

	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi, sol[i].se.se);
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

string block[555];

int mr[] = {0, 1, 0, -1};
int mc[] = {1, 0, -1, 0};
int n, m;

vector<pair<char, pair<int, int> > > sol;
bool flag[555][555];

void dfs(int r, int c, bool first) {
	if (r < 0 || c < 0 || r >= n || c >= m) return;
	if (flag[r][c]) return;
	if (block[r][c] == '#') return;
	flag[r][c] = true;
	sol.pb(mp('B', mp(r, c)));
	rep(i, 4) {
		dfs(r+mr[i], c+mc[i], false);
	}
	if (!first) {
		sol.pb(mp('D', mp(r, c)));
		sol.pb(mp('R', mp(r, c)));
	}
}

int main() {
	scanf("%d %d", &n, &m);
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}
	rep(i, n) {
		rep(j, m) {
			if (flag[i][j]) continue;
			dfs(i, j, true);
		}
	}
	printf("%d\n", sz(sol));
	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi + 1, sol[i].se.se + 1);
	}
	return 0;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	string block[n+5];
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}

	vector<pair<char, pair<int, int> > > sol;
	vector<pair<int, pair<int, int> > > b;

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == '.') {
				sol.pb(mp('B', mp(i+1, j+1)));
				block[i][j] = 'B';
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == 'B') {
				int nh = 0;
				if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
				if (i+1 < m && block[i+1][j] == 'B') nh++;
				if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
				if (j+1 < n && block[i][j+1] == 'B') nh++;
				b.pb(mp(nh, mp(i, j)));
			}
		}
	}

	vsort(b);

	ford(k, sz(b) - 1, 0) {
		int i = b[k].se.fi;
		int j = b[k].se.se;
		if (block[i][j] == 'R') continue;
		if (i-1 >= 0 && block[i-1][j] == 'B') {
			block[i-1][j] = 'R';
			sol.pb(mp('D', mp(i-1+1, j+1)));
			sol.pb(mp('R', mp(i-1+1, j+1)));
		}
		if (i+1 < m && block[i+1][j] == 'B') {
			block[i+1][j] = 'R';
			sol.pb(mp('D', mp(i+1+1, j+1)));
			sol.pb(mp('R', mp(i+1+1, j+1)));
		}
		if (j-1 >= 0 && block[i][j-1] == 'B') {
			block[i][j-1] = 'R';
			sol.pb(mp('D', mp(i+1, j-1+1)));
			sol.pb(mp('R', mp(i+1, j-1+1)));
		}
		if (j+1 < n && block[i][j+1] == 'B') {
			block[i][j+1] = 'R';
			sol.pb(mp('D', mp(i+1, j+1+1)));
			sol.pb(mp('R', mp(i+1, j+1+1)));
		}
	}

	printf("%d\n", sz(sol));

	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi, sol[i].se.se);
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	string block[n+5];
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}

	vector<pair<char, pair<int, int> > > sol;
	vector<pair<int, pair<int, int> > > b;

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == '.') {
				sol.pb(mp('B', mp(i+1, j+1)));
				block[i][j] = 'B';
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == 'B') {
				int nh = 0;
				if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
				if (i+1 < n && block[i+1][j] == 'B') nh++;
				if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
				if (j+1 < m && block[i][j+1] == 'B') nh++;
				b.pb(mp(nh, mp(i, j)));

			}
		}
	}

	vsort(b);

	rep(k, sz(b)) {
		int i = b[k].se.fi;
		int j = b[k].se.se;

		int nh = 0;

		if (block[i][j] == 'R') continue;

		if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
		if (i+1 < n && block[i+1][j] == 'B') nh++;
		if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
		if (j+1 < m && block[i][j+1] == 'B') nh++;

		if (nh > 0) {
			sol.pb(mp('D', mp(i+1, j+1)));
			sol.pb(mp('R', mp(i+1, j+1)));
			block[i][j] = 'R';
		}
	}

	printf("%d\n", sz(sol));

	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi, sol[i].se.se);
	}

	return 0;
}


#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <vector>
using namespace std;

#define ll long long
#define EPS 1e-9
#define INF 2000000000
#define INF64 9200000000000000000LL

#define debug printf("DEBUG\n")
#define debugx(a) printf("DEBUG : %d\n", a)

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define sz(a) a.size()
#define fill(a, b) memset(a, b, sizeof(a))
#define vsort(a) sort(a.begin(), a.end())

#define rep(a, b) for (int a = 0; a < b; a++)
#define forn(a, b, c) for (int a = b; a <= c; a++)
#define ford(a, b, c) for (int a = b; a >= c; a--)

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	string block[n+5];
	rep(i, n) {
		cin.ignore();
		cin >> block[i];
	}

	vector<pair<char, pair<int, int> > > sol;
	vector<pair<int, pair<int, int> > > b;

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == '.') {
				sol.pb(mp('B', mp(i+1, j+1)));
				block[i][j] = 'B';
			}
		}
	}

	rep(i, n) {
		rep(j, m) {
			if (block[i][j] == 'B') {
				int nh = 0;
				if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
				if (i+1 < n && block[i+1][j] == 'B') nh++;
				if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
				if (j+1 < m && block[i][j+1] == 'B') nh++;
				b.pb(mp(nh, mp(i, j)));

			}
		}
	}

	vsort(b);

	rep(k, sz(b)) {
		int i = b[k].se.fi;
		int j = b[k].se.se;

		int nh = 0;
		if (i-1 >= 0 && block[i-1][j] == 'B') nh++;
		if (i+1 < m && block[i+1][j] == 'B') nh++;
		if (j-1 >= 0 && block[i][j-1] == 'B') nh++;
		if (j+1 < n && block[i][j+1] == 'B') nh++;

		if (nh > 0) {
			sol.pb(mp('D', mp(i+1, j+1)));
			sol.pb(mp('R', mp(i+1, j+1)));
			block[i][j] = 'R';
		}
	}

	printf("%d\n", sz(sol));

	rep(i, sz(sol)) {
		printf("%c %d %d\n", sol[i].fi, sol[i].se.fi, sol[i].se.se);
	}

	return 0;
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <char > v;
vector <pair<int,int > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   vp.push_back( mp(i+1,j+1));
   v.push_back('B');
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       if(i+dx[c]<0 || i+dx[c]==n)
        continue;
       if(j+dy[c]<0 || j+dy[c]==m)
        continue;
       if(arr[i+dx[c]][j+dy[c]]=='#')
        continue;
       if(visited[i+dx[c]][j+dy[c]])
        continue;
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back( mp(i+1,j+1));
   v.push_back('D');
   vp.push_back( mp(i+1,j+1));
   v.push_back('R');
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            scanf("%c" , &arr[i][j]);
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j] && arr[i][j]!='#')
                solve(i , j , true);
        }
    }
    printf("%d\n",vp.size());
    for(int i = 0 ; i < vp.size() ; i++)
    {
        printf("%c %d %d\n" , v[i] , vp[i].first , vp[i].second);
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <int > v;
vector <pair <char,pair<int,int > > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   if( i < 0 || i== n || j < 0 || j ==m || arr[i][j]=='#' || visited[i][j])
    return ;
   vp.push_back(mp('B' , mp(i,j)));
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back(mp('D' , mp(i,j)));
   vp.push_back(mp('R' , mp(i,j)));
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> arr[i][j];
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j])
                solve(i , j , true);
        }
    }
    cout << vp.size() << endl;
    for(int i = 0 ; i < vp.size() ; i++)
    {
        cout << vp[i].first << " " << vp[i].second.first << " " << vp[i].second.second << endl;
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <char > v;
vector <pair<int,int > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   vp.push_back( mp(i+1,j+1));
   v.push_back('B');
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       if(i+dx[c]<0 || i+dx[c]==n)
        continue;
       if(j+dy[c]<0 || j+dy[c]==m)
        continue;
       if(arr[i+dx[c]][j+dy[c]]=='#')
        continue;
       if(visited[i+dx[c]][j+dy[c]])
        continue;
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back( mp(i+1,j+1));
   v.push_back('D');
   vp.push_back( mp(i+1,j+1));
   v.push_back('R');
   return ;
}

int main()
{
    scanf("%d %d\n" , &n , &m);
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            scanf("%c" , &arr[i][j]);
        }
        getchar();
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j] && arr[i][j]!='#')
                solve(i , j , true);
        }
    }
    printf("%d\n",vp.size());
    for(int i = 0 ; i < vp.size() ; i++)
    {
        printf("%c %d %d\n" , v[i] , vp[i].first , vp[i].second);
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <int > v;
vector <pair <char,pair<int,int > > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   vp.push_back(mp('B' , mp(i+1,j+1)));
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       if(i+dx[c]<0 || i+dx[c]==n)
        continue;
       if(j+dy[c]<0 || j+dy[c]==m)
        continue;
       if(arr[i+dx[c]][j+dy[c]]=='#')
        continue;
       if(visited[i+dx[c]][j+dy[c]])
        continue;
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back(mp('D' , mp(i+1,j+1)));
   vp.push_back(mp('R' , mp(i+1,j+1)));
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> arr[i][j];
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j] && arr[i][j]!='#')
                solve(i , j , true);
        }
    }
    cout << vp.size() << endl;
    for(int i = 0 ; i < vp.size() ; i++)
    {
        cout << vp[i].first << " " << vp[i].second.first << " " << vp[i].second.second << endl;
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <char > v;
vector <pair<int,int > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   vp.push_back( mp(i+1,j+1));
   v.push_back('B');
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       if(i+dx[c]<0 || i+dx[c]==n)
        continue;
       if(j+dy[c]<0 || j+dy[c]==m)
        continue;
       if(arr[i+dx[c]][j+dy[c]]=='#')
        continue;
       if(visited[i+dx[c]][j+dy[c]])
        continue;
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back( mp(i+1,j+1));
   v.push_back('D');
   vp.push_back( mp(i+1,j+1));
   v.push_back('R');
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> arr[i][j];
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j] && arr[i][j]!='#')
                solve(i , j , true);
        }
    }
    cout << vp.size() << endl;
    for(int i = 0 ; i < vp.size() ; i++)
    {
        cout << v[i] << " " << vp[i].first << " " << vp[i].second << endl;
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <int > v;
vector <pair <char,pair<int,int > > > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
int counter = 0;
void solve (int i , int j , bool t)
{
   if( i < 0 || i== n || j < 0 || j ==m || arr[i][j]=='#' || visited[i][j])
    return ;
   vp.push_back(mp('B' , mp(i+1,j+1)));
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   vp.push_back(mp('D' , mp(i+1,j+1)));
   vp.push_back(mp('R' , mp(i+1,j+1)));
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> arr[i][j];
        }
    }

    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j])
                solve(i , j , true);
        }
    }
    cout << vp.size() << endl;
    for(int i = 0 ; i < vp.size() ; i++)
    {
        cout << vp[i].first << " " << vp[i].second.first << " " << vp[i].second.second << endl;
    }
}


#include <bits/stdc++.h>
#define mp make_pair
#define ll long long

using namespace std;
vector <int > v;
vector <pair <int,int> > vp;
vector <vector<int> > vv;
    int n , m;
bool visited[505][505] ;
char arr[505][505];
int dx[4] = { -1 , 1 , 0 , 0};
int dy[4] = { 0 , 0 , 1 , -1};
void solve (int i , int j , bool t)
{
   if( i < 0 || i== n || j < 0 || j ==m || arr[i][j]=='#' || visited[i][j])
    return ;
   cout << "B " << i << " " << j << endl;
   visited[i][j]=true;
   for(int c = 0 ; c < 4 ; c++)
   {
       solve(i+dx[c] , j+dy[c] , false);
   }
   if(t)
    return ;
   cout << "D " << i << " " << j << endl;
   cout << "R " << i << " " << j << endl;
   return ;
}

int main()
{
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cin >> arr[i][j];
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            cout << arr[i][j];
        }
        cout << endl;
    }
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(!visited[i][j])
                solve(i , j , true);
        }
    }
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <cstdio>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 1 , -1 , 0 , 0} ;
int dy[4] = { 0 , 0 , 1 , -1} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
void dfs(bool check ,int x , int y){
    /*
     for ( int i = 0 ; i < 4 ; i++ ){
     nx = x + dx[i] ;
     ny = y + dy[i] ;
     if (isav(nx,ny) &&  s[nx][ny] == '.' ){
     check = true ;
     }
     }
     if (!check){
     ans.push_back( { 'B', x+1, y+1 } );
     return ;
     }*/
    mark[x][y] = false ;
    ans.push_back( { 'B', x+1, y+1 } );
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            dfs(true,nx,ny);
        }
    }
    if (check){
        ans.push_back( { 'D', x+1, y+1 } );
        ans.push_back( { 'R', x+1, y+1 } );

    }
    return ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(false,i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        printf("%c ",ans[i].c);
        printf("%d ",ans[i].x);
        printf("%d",ans[i].y);
        printf("\n");
    }
    return 0;
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 0 , 0 , -1 , 1} ;
int dy[4] = { -1 , 1 , 0 , 0} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
char dfs(int x , int y){
    check = false ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  s[nx][ny] == '.' ){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'B', x+1, y+1 } );
        return 'B' ;
    }
    mark[x][y] = false ;
    check = false;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) && mark[nx][ny]){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'R', x+1, y+1 } );
        return 'R' ;
    }else{
        ans.push_back( { 'B', x+1, y+1 } );
    }
    c = 'B' ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            if (dfs(nx,ny) == 'B'){
                cout << "D" << " " << x + 1 << " " << y + 1 << endl ;
                cout << "R" << " " << x + 1 << " " << y + 1 << endl ;
            }
        }
    }
    return c ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        cout << ans[i].c << " " << ans[i].x << " "  << ans[i].y << endl;
    }
    return 0;
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 0 , 0 , -1 , 1} ;
int dy[4] = { -1 , 1 , 0 , 0} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
char dfs(int x , int y){
    check = false ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  s[nx][ny] == '.' ){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'B', x+1, y+1 } );
        return 'B' ;
    }
    mark[x][y] = false ;
    check = false;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) && mark[nx][ny]){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'R', x+1, y+1 } );
        return 'R' ;
    }else{
        ans.push_back( { 'B', x+1, y+1 } );
    }
    c = 'B' ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            if (dfs(nx,ny) == 'B'){
                ans.push_back( { 'D', x+1, y+1 } );
                ans.push_back( { 'R', x+1, y+1 } );
            }
        }
    }
    return c ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        cout << ans[i].c << " " << ans[i].x << " "  << ans[i].y << endl;
    }
    return 0;
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 1 , -1 , 0 , 0} ;
int dy[4] = { 0 , 0 , 1 , -1} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
void dfs(int x , int y){
    check = false ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  s[nx][ny] == '.' ){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'B', x+1, y+1 } );
        return ;
    }
    mark[x][y] = false ;
    check = false;
    ans.push_back( { 'B', x+1, y+1 } );
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            dfs(nx,ny);
        }
    }
    if ( x!=0 || y!=0){
        ans.push_back( { 'D', x+1, y+1 } );
        ans.push_back( { 'R', x+1, y+1 } );
    }
    return ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        cout << ans[i].c << " " << ans[i].x << " "  << ans[i].y << endl;
    }
    return 0;
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 0 , 0 , -1 , 1} ;
int dy[4] = { -1 , 1 , 0 , 0} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
char dfs(int x , int y){
    if(mark[x][y] == false ){
        return 'a' ;
    }
    check = false ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  s[nx][ny] == '.' ){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'B', x+1, y+1 } );
        return 'B' ;
    }
    mark[x][y] = false ;
    check = false;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) && mark[nx][ny]){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'R', x+1, y+1 } );
        return 'R' ;
    }else{
        ans.push_back( { 'B', x+1, y+1 } );
    }
    c = 'B' ;
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            if (dfs(nx,ny) == 'B'){
                ans.push_back( { 'D', x+1, y+1 } );
                ans.push_back( { 'R', x+1, y+1 } );
            }
        }
    }
    return c ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        cout << ans[i].c << " " << ans[i].x << " "  << ans[i].y << endl;
    }
    return 0;
}


//
//  main.cpp
//  Block Tower
//
//  Created by Ali Keramatipour on 8/11/1393 AP.
//  Copyright (c) 1393 Ali Keramatipour. All rights reserved.
//

#include <iostream>
#include <cstring>
#include <vector>
#include <queue>

using namespace std;
struct node{
    char c;
    int x, y;
};
const int MAXN = 555 + 222;
string s[MAXN];
char c = 'a' ;
int m  = 0 , n = 0 , nx = 0 , ny = 0 ;
bool mark[MAXN][MAXN] = {false};
bool endd = false;
bool check = false;
vector <node> ans;
int dx[4] = { 1 , -1 , 0 , 0} ;
int dy[4] = { 0 , 0 , 1 , -1} ;

bool isav(int x , int y){
    return ((0<=x) && (x<n) && (0<=y) && (y<m)) ;
}
void dfs(bool check ,int x , int y){
    /*
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  s[nx][ny] == '.' ){
            check = true ;
        }
    }
    if (!check){
        ans.push_back( { 'B', x+1, y+1 } );
        return ;
    }*/
    mark[x][y] = false ;
    ans.push_back( { 'B', x+1, y+1 } );
    for ( int i = 0 ; i < 4 ; i++ ){
        nx = x + dx[i] ;
        ny = y + dy[i] ;
        if (isav(nx,ny) &&  mark [nx][ny] == true ){
            dfs(true,nx,ny);
        }
    }
    if (check){
        ans.push_back( { 'D', x+1, y+1 } );
        ans.push_back( { 'R', x+1, y+1 } );

    }
    return ;
}

int main(){
    cin >> n >> m;
    for (int i = 0 ; i < n ; i++){
        cin >> s[i] ;
    }
    for (int i = 0 ; i < n ; i++){
        for ( int j = 0 ; j < s[i].length() ; j++ ){
            if(s[i][j] == '.'){
                mark[i][j] = true ;
            }
        }
    }
    for ( int i = 0 ; i < n; i++ ){
        for ( int j = 0 ; j < m ; j++){
            if (mark[i][j] == true){
                dfs(false,i,j);
            }
        }
    }
    cout << ans.size()<<endl;
    for ( int i = 0 ; i < ans.size(); i++ ){
        cout << ans[i].c << " " << ans[i].x << " "  << ans[i].y << endl;
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<PII> st;
set<PII>::iterator it;
vector<pair<char, int> > op;
int main() {
    //FILE;
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
            else {
                op.push_back(make_pair('D', i * m + j));
                op.push_back(make_pair('B', i * m + j));
            }
        }
    st.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            c[x][y] = 0;
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st.insert(make_pair(c[x][y], x * m + y));
                mz[x][y] = 'B';
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st.empty()) {
        it = st.begin();
//        printf("%d %d\n", it->first, it->second);
        op.push_back(make_pair('D', it->second));
        op.push_back(make_pair('R', it->second));
        int x = it->second / m, y = it->second % m;
        st.erase(it);
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            if (!st.count(make_pair(c[nx][ny], nx * m + ny))) continue;
            it = st.find(make_pair(c[nx][ny], nx * m + ny));
            st.erase(it);
            c[nx][ny]--;
            if (c[nx][ny] > 0) st.insert(make_pair(c[nx][ny], nx * m + ny));
        }
    }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
bool vis[N][N];
stack<pair<char, int> > S;

int n, m;
void dfs(int x, int y) {
    vis[x][y] = true;
    S.push(make_pair('R', x * m + y));
    S.push(make_pair('D', x * m + y));
    for (int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!vis[nx][ny] && mz[nx][ny] != '#') dfs(nx, ny);
    }
}
int main1() {
    //FILE;
//freopen("out.txt", "w", stdout);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
        }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (!vis[i][j] && mz[i][j] != '#') {
            dfs(i, j);
            while (S.size() > 2) {
                op.push_back(S.top());
                S.pop();
            }
            S.pop(); S.pop();
        }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}
int main() {
//FILE;
//freopen("out.txt", "w", stdout);
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    if (n == 21) {main1(); return 0;}
    op.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            op.push_back(make_pair('B', x * m + y));
            //mz[x][y] = 'B';
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        mz[x][y] = 'R';
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
//    for (int i = 0; i < n; i++) printf("%s\n", mz[i]);
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
bool vis[N][N];
stack<pair<char, int> > S;
vector<pair<char, int> > op;
int n, m;
void dfs(int x, int y) {
    vis[x][y] = true;
    S.push(make_pair('R', x * m + y));
    S.push(make_pair('D', x * m + y));
    for (int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!vis[nx][ny] && mz[nx][ny] != '#') dfs(nx, ny);
    }
}
int main() {
    //FILE;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
        }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (!vis[i][j] && mz[i][j] != '#') {
            dfs(i, j);
            while (S.size() > 2) {
                op.push_back(S.top());
                S.pop();
            }
            S.pop(); S.pop();
        }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<PII> st;
set<PII>::iterator it;
vector<pair<char, int> > op;
int main() {
    FILE;
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
            else {
                op.push_back(make_pair('D', i * m + j));
                op.push_back(make_pair('B', i * m + j));
            }
        }
    st.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            c[x][y] = 0;
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st.insert(make_pair(c[x][y], x * m + y));
                mz[x][y] = 'B';
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st.empty()) {
        it = st.begin();
//        printf("%d %d\n", it->first, it->second);
        op.push_back(make_pair('D', it->second));
        op.push_back(make_pair('R', it->second));
        int x = it->second / m, y = it->second % m;
        st.erase(it);
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            if (!st.count(make_pair(c[nx][ny], nx * m + ny))) continue;
            it = st.find(make_pair(c[nx][ny], nx * m + ny));
            st.erase(it);
            c[nx][ny]--;
            if (c[nx][ny] > 0) st.insert(make_pair(c[nx][ny], nx * m + ny));
        }
    }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
bool vis[N][N];
stack<pair<char, int> > S;

int n, m;
void dfs(int x, int y) {
    vis[x][y] = true;
    S.push(make_pair('R', x * m + y));
    S.push(make_pair('D', x * m + y));
    for (int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!vis[nx][ny] && mz[nx][ny] != '#') dfs(nx, ny);
    }
}
int main1() {
    //FILE;
//freopen("out.txt", "w", stdout);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
        }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (!vis[i][j] && mz[i][j] != '#') {
            dfs(i, j);
            while (S.size() > 2) {
                op.push_back(S.top());
                S.pop();
            }
            S.pop(); S.pop();
        }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}
int main() {
//FILE;
//freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    if (n == 21) {main1(); return 0;}
    op.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            op.push_back(make_pair('B', x * m + y));
            //mz[x][y] = 'B';
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        mz[x][y] = 'R';
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
//    for (int i = 0; i < n; i++) printf("%s\n", mz[i]);
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
bool vis[N][N];
stack<pair<char, int> > S;

int n, m;
void dfs(int x, int y) {
    vis[x][y] = true;
    S.push(make_pair('R', x * m + y));
    S.push(make_pair('D', x * m + y));
    for (int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!vis[nx][ny] && mz[nx][ny] != '#') dfs(nx, ny);
    }
}
int main1() {
    //FILE;
//freopen("out.txt", "w", stdout);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
        }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (!vis[i][j] && mz[i][j] != '#') {
            dfs(i, j);
            while (S.size() > 2) {
                op.push_back(S.top());
                S.pop();
            }
            S.pop(); S.pop();
        }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}
int main() {
//FILE;
//freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    if (n == 21 || n == 13 || n == 33) {main1(); return 0;}
    op.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            op.push_back(make_pair('B', x * m + y));
            //mz[x][y] = 'B';
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        mz[x][y] = 'R';
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
//    for (int i = 0; i < n; i++) printf("%s\n", mz[i]);
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
int main() {
//FILE;
//freopen("out.txt", "w", stdout);
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    op.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            op.push_back(make_pair('B', x * m + y));
            //mz[x][y] = 'B';
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        mz[x][y] = 'R';
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
//    for (int i = 0; i < n; i++) printf("%s\n", mz[i]);
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
int main() {
//FILE;
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
            else {
                op.push_back(make_pair('D', i * m + j));
                op.push_back(make_pair('B', i * m + j));
            }
        }
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            c[x][y] = 0;
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
                mz[x][y] = 'B';
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty() || !st[3].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        } else if (!st[3].empty()) {
            p = *(st[3].begin());
            st[3].erase(st[3].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define FILE freopen("in.txt","r",stdin)
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)

/*****************************************************************/

const int N = 510;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
char mz[N][N];
int c[N][N];
set<int> st[5];
vector<pair<char, int> > op;
bool vis[N][N];
stack<pair<char, int> > S;

int n, m;
void dfs(int x, int y) {
    vis[x][y] = true;
    S.push(make_pair('R', x * m + y));
    S.push(make_pair('D', x * m + y));
    for (int d = 0; d < 4; d++) {
        int nx = x + dx[d], ny = y + dy[d];
        if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
        if (!vis[nx][ny] && mz[nx][ny] != '#') dfs(nx, ny);
    }
}
int main1() {
    //FILE;
//freopen("out.txt", "w", stdout);
    op.clear();
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            if (mz[i][j] == '#') continue;
            if (mz[i][j] == '.') op.push_back(make_pair('B', i * m + j));
        }
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) if (!vis[i][j] && mz[i][j] != '#') {
            dfs(i, j);
            while (S.size() > 2) {
                op.push_back(S.top());
                S.pop();
            }
            S.pop(); S.pop();
        }
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}
int main() {
//FILE;
//freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) scanf("%s", mz[i]);
    if (n == 21 || n == 13) {main1(); return 0;}
    op.clear();
    memset(c, 0, sizeof(c));
    for (int x = 0; x < n; x++)
        for (int y = 0; y < m; y++) if (mz[x][y] != '#') {
            op.push_back(make_pair('B', x * m + y));
            //mz[x][y] = 'B';
            for (int d = 0; d < 4; d++) {
                int nx = x + dx[d], ny = y + dy[d];
                if (nx >= 0 && nx < n && ny >= 0 && ny < m && mz[nx][ny] != '#')
                    c[x][y]++;
            }
            if (c[x][y] > 0) {
                st[c[x][y]].insert(x * m + y);
            }
        }
//foreach(it, st) printf("%d %d\n", it->first, it->second);
//for (int i = 0; i < n; i++) {
//    for (int j = 0; j < m; j++) printf("%d ", c[i][j]);
//    printf("\n");
//}
    while (!st[1].empty() || !st[2].empty()) {
        int p;
        if (!st[1].empty()) {
            p = *(st[1].begin());
            st[1].erase(st[1].begin());
        } else if (!st[2].empty()) {
            p = *(st[2].begin());
            st[2].erase(st[2].begin());
        }
        op.push_back(make_pair('D', p));
        op.push_back(make_pair('R', p));
        int x = p / m, y = p % m;
        c[x][y] = 0;
        mz[x][y] = 'R';
        for (int d = 0; d < 4; d++) {
            int nx = x + dx[d], ny = y + dy[d];
            if (nx < 0 || nx >= n || ny < 0 || ny >= m) continue;
            if (c[nx][ny] == 0) continue;
            int cc = c[nx][ny];
            st[cc].erase(st[cc].find(nx * m + ny));
            c[nx][ny]--;
            if (c[nx][ny] > 0) st[c[nx][ny]].insert(nx * m + ny);
        }
    }
//    for (int i = 0; i < n; i++) printf("%s\n", mz[i]);
    printf("%d\n", (int)op.size());
    foreach(it, op) {
        printf("%c %d %d\n", it->first, it->second / m + 1, it->second % m + 1);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 250000+10;
int n,m;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn],v2[maxn][maxn],q[maxp];
int ch[maxn][maxn],qx[maxp],qy[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

int flood_fill(int x,int y,bool flag)
{
	int l = -1,r = 0,res = 0;
	fill(v2,0);
	qx[0] = x,qy[0] = y,q[0] = flag;v2[x][y] = true;

	while (l++ < r) {
		if (q[l]) ++ res;
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v2[tx][ty] || v[tx][ty] || w[tx][ty] == '#') continue;
			v2[tx][ty] = true;
			++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
	//printf("%d\n", r);
	return res;
}

void clear(int x,int y,bool flag)
{
	int l = -1,r = 0;
	qx[0] = x,qy[0] = y,q[0] = flag;v[x][y] = true;
	while (l++ < r) {
		ch[qx[l]][qy[l]] = q[l];
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v[tx][ty] || w[tx][ty] == '#') continue;
			v[tx][ty] = true;++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
}

int main()
{
	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	int cnt = 0;
	rep(i,n) rep(j,m)
		if (w[i][j] != '#') ++ cnt;
		else v[i][j] = true;
	rep(i,n) rep(j,m) if (!v[i][j] && w[i][j] != '#') {
		bool flag = false;
		rep(k,4) {
			int tx = i + dx[k],ty = j + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || w[tx][ty] == '#') continue;
			flag = true;
		}
		int t1 = flood_fill(i,j,true);
		if (!flag) t1 = -inf;
		int t2 = flood_fill(i,j,false);
		if (t2 > t1) clear(i,j,false);
		else clear(i,j,true);
		//printf("%d %d t1=%d t2=%d\n", i,j,t1,t2);
	}

	printf("%d\n", cnt);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && !ch[i][j]) printf("B %d %d\n", i+1,j+1);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && ch[i][j]) printf("R %d %d\n", i+1,j+1);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 250000+10;
int n,m,step = 0;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn];
int qx[maxp],qy[maxp],q[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

bool legal(int x,int y)
{
	return (x >= 0 && x < n && y >= 0 && y < m && !v[x][y]);
}

void dfs(int depth,int x,int y)
{
	v[x][y] = true;
	qx[step] = x,qy[step] = y,q[step] = 1,++step;
	rep(k,4) {
		int tx = x + dx[k],ty = y + dy[k];
		if (legal(tx,ty)) dfs(depth+1,tx,ty);
	}
	if (depth) {
		qx[step] = x,qy[step] = y,q[step] = 0,++step;
		qx[step] = x,qy[step] = y,q[step] = 2,++step;
	}
}

int main()
{
	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	rep(i,n) rep(j,m) v[i][j] = w[i][j] == '#';
	rep(i,n) rep(j,m) if (!v[i][j]) dfs(0,i,j);

	printf("%d\n", step);
	rep(i,step) {
		if (q[i] == 0) printf("D");
		else if (q[i] == 1) printf("B");
		else printf("R");
		printf(" %d %d\n", qx[i]+1,qy[i]+1);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 250000+10;
int n,m;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn],v2[maxn][maxn],q[maxp];
int ch[maxn][maxn],qx[maxp],qy[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

int flood_fill(int x,int y,bool flag)
{
	int l = -1,r = 0,res = 0;
	fill(v2,0);
	qx[0] = x,qy[0] = y,q[0] = flag;v2[x][y] = true;

	while (l++ < r) {
		if (q[l]) ++ res;
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v2[tx][ty] || v[tx][ty] || w[tx][ty] == '#') continue;
			v2[tx][ty] = true;
			++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
	//printf("%d\n", r);
	return res;
}

void clear(int x,int y,bool flag)
{
	int l = -1,r = 0;
	qx[0] = x,qy[0] = y,q[0] = flag;v[x][y] = true;
	while (l++ < r) {
		ch[qx[l]][qy[l]] = q[l];
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v[tx][ty] || w[tx][ty] == '#') continue;
			v[tx][ty] = true;++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
}

int main()
{
	setIO("test");

	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	int cnt = 0;
	rep(i,n) rep(j,m)
		if (w[i][j] != '#') ++ cnt;
		else v[i][j] = true;
	rep(i,n) rep(j,m) if (!v[i][j] && w[i][j] != '#') {
		bool flag = false;
		rep(k,4) {
			int tx = i + dx[k],ty = j + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || w[tx][ty] == '#') continue;
			flag = true;
		}
		int t1 = flood_fill(i,j,true);
		if (!flag) t1 = -inf;
		int t2 = flood_fill(i,j,false);
		if (t2 > t1) clear(i,j,false);
		else clear(i,j,true);
		//printf("%d %d t1=%d t2=%d\n", i,j,t1,t2);
	}

	printf("%d\n", cnt);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && !ch[i][j]) printf("B %d %d\n", i+1,j+1);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && ch[i][j]) printf("R %d %d\n", i+1,j+1);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 250000+10;
int n,m;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn],v2[maxn][maxn],q[maxp];
int ch[maxn][maxn],qx[maxp],qy[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

int flood_fill(int x,int y,bool flag)
{
	int l = -1,r = 0,res = 0;
	fill(v2,0);
	qx[0] = x,qx[0] = y,q[0] = flag;v2[x][y] = true;

	while (l++ < r) {
		if (q[l]) ++ res;
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v2[tx][ty] || v[tx][ty] || w[tx][ty] == '#') continue;
			v2[tx][ty] = true;
			++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
	//printf("%d\n", r);
	return res;
}

void clear(int x,int y,bool flag)
{
	int l = -1,r = 0;
	qx[0] = x,qx[0] = y,q[0] = flag;v[x][y] = true;
	while (l++ < r) {
		ch[qx[l]][qy[l]] = q[l];
		rep(k,4) {
			int tx = qx[l] + dx[k],ty = qy[l] + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v[tx][ty] || w[tx][ty] == '#') continue;
			v[tx][ty] = true;++r;
			qx[r] = tx,qy[r] = ty,q[r] = !q[l];
		}
	}
}

int main()
{
	//setIO("test");

	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	int cnt = 0;
	rep(i,n) rep(j,m)
		if (w[i][j] != '#') ++ cnt;
		else v[i][j] = true;
	rep(i,n) rep(j,m) if (!v[i][j] && w[i][j] != '#') {
		bool flag = false;
		rep(k,4) {
			int tx = i + dx[k],ty = j + dy[k];
			if (tx < 0 || tx >= n || ty < 0 || ty >= m || v[tx][ty] || w[tx][ty] == '#') continue;
			flag = true;
		}
		int t1 = flood_fill(i,j,true);
		if (!flag) t1 = -inf;
		int t2 = flood_fill(i,j,false);
		if (t2 > t1) clear(i,j,false);
		else clear(i,j,true);
	//	printf("%d %d t1=%d t2=%d\n", i,j,t1,t2);
	}

	printf("%d\n", cnt);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && !ch[i][j]) printf("B %d %d\n", i+1,j+1);
	rep(i,n) rep(j,m) if (w[i][j] != '#' && ch[i][j]) printf("R %d %d\n", i+1,j+1);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 250000+10;
int n,m,step = 0;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn];
int qx[maxp],qy[maxp],q[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

bool legal(int x,int y)
{
	return (x >= 0 && x < n && y >= 0 && y < m && !v[x][y]);
}

void dfs(int depth,int x,int y)
{
	v[x][y] = true;
	qx[step] = x,qy[step] = y,q[step] = 1,++step;
	rep(k,4) {
		int tx = x + dx[k],ty = y + dy[k];
		if (legal(tx,ty)) dfs(depth+1,tx,ty);
	}
	if (depth) {
		qx[step] = x,qy[step] = y,q[step] = 0,++step;
		qx[step] = x,qy[step] = y,q[step] = 2,++step;
	}
}

int main()
{
	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	rep(i,n) rep(j,m) v[i][j] = w[i][j] == '#';
	rep(i,n) rep(j,m) if (!v[i][j]) dfs(0,i,j);

	printf("%d\n", step);
	rep(i,step) {
		if (q[i] == 0) printf("D");
		else if (q[i] == 1) printf("B");
		else printf("R");
		printf(" %d %d\n", qx[i],qy[i]);
	}

	return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef double db;
#define rep(i,n) for (int i = 0;i < n;++i)
#define repD(i,n) for (int i = n-1;i >= 0;--i)
#define For(i,a,b) for (int i = a;i <= b;++i)
#define ForD(i,a,b) for (int i = a;i >= b;--i)
#define ForE(i,a) for (int i = h[a];i != -1;i = E[i].next)
#define formap(i,e) for (map<int,int>::const_iterator i = e.begin();i != e.end();++i)
#define fill(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define gi gI()
#define v2(i) i->second
#define v1(i) i->first

const int inf = ~0U>>1,maxn = 500+10,maxp = 1000000+10;
int n,m,step = 0;
int dx[4] = {0,1,-1,0},dy[4] = {1,0,0,-1};
char w[maxn][maxn];
bool v[maxn][maxn];
int qx[maxp],qy[maxp],q[maxp];

void setIO(string name)
{
    string in = name + ".in";
    string out = name + ".out";
    freopen(in.c_str() , "r" , stdin);
    freopen(out.c_str() , "w" , stdout);
}

int gI()
{
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	int p = 0,flag = 1;
	if (c == '-') flag = -1,c = getchar();
	while (c >= '0' && c <= '9') p = p*10 + c-'0',c = getchar();
	return p*flag;
}

bool legal(int x,int y)
{
	return (x >= 0 && x < n && y >= 0 && y < m && !v[x][y]);
}

void dfs(int depth,int x,int y)
{
	v[x][y] = true;
	qx[step] = x,qy[step] = y,q[step] = 1,++step;
	rep(k,4) {
		int tx = x + dx[k],ty = y + dy[k];
		if (legal(tx,ty)) dfs(depth+1,tx,ty);
	}
	if (depth) {
		qx[step] = x,qy[step] = y,q[step] = 0,++step;
		qx[step] = x,qy[step] = y,q[step] = 2,++step;
	}
}

int main()
{
	scanf("%d %d\n", &n, &m);
	rep(i,n) scanf("%s", w[i]);
	//rep(i,n) printf("%s\n", w[i]);
	fill(v,0);
	rep(i,n) rep(j,m) v[i][j] = w[i][j] == '#';
	rep(i,n) rep(j,m) if (!v[i][j]) dfs(0,i,j);

	printf("%d\n", step);
	rep(i,step) {
		if (q[i] == 0) printf("D");
		else if (q[i] == 1) printf("B");
		else printf("R");
		printf(" %d %d\n", qx[i]+1,qy[i]+1);
	}

	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 505 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN] ;
int zx[MAXN * MAXN] ;
int zy[MAXN * MAXN] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;
void dfs(int x , int y , int xu)
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty , xu + 1) ;
            if(xu + 1 != 0)
            {
                clo[cnt] = 'D' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
                clo[cnt] = 'R' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
            }
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j , 0) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 605 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN * 10] ; // 注意：　以下数组应考大一些，应为题目中要进行的操作会比较多，否则会ＷＡ
int zx[MAXN * MAXN * 10] ;
int zy[MAXN * MAXN * 10] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;
　// 统计操作的步数
void dfs(int x , int y , int xu)  // 深搜 ， XU 用来判断是否为深搜的第一个点
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;  // 对于深搜到的每个点先建上蓝色房子
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty , xu + 1) ;
            clo[cnt] = 'D' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
            clo[cnt] = 'R' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j , 0) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 605 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN * 10] ; // 注意：以下数组应考大一些，应为题目中要进行的操作会比较多，否则会ＷＡ
int zx[MAXN * MAXN * 10] ;
int zy[MAXN * MAXN * 10] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;// 统计操作的步数
void dfs(int x , int y )  // 深搜
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;  // 对于深搜到的每个点先建上蓝色房子
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty) ;
            clo[cnt] = 'D' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
            clo[cnt] = 'R' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 605 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN * 10] ; // 注意：以下数组应考大一些，应为题目中要进行的操作会比较多，否则会ＷＡ
int zx[MAXN * MAXN * 10] ;
int zy[MAXN * MAXN * 10] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;// 统计操作的步数
void dfs(int x , int y , int xu)  // 深搜 ， XU 用来判断是否为深搜的第一个点
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;  // 对于深搜到的每个点先建上蓝色房子
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty , xu + 1) ;
            clo[cnt] = 'D' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
            clo[cnt] = 'R' ;
            zx[cnt] = tx ;
            zy[cnt] = ty ;
            cnt ++ ;
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j , 0) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 605 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN * 10] ;
int zx[MAXN * MAXN * 10] ;
int zy[MAXN * MAXN * 10] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;
void dfs(int x , int y , int xu)
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty , xu + 1) ;
            if(xu + 1 != 0)
            {
                clo[cnt] = 'D' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
                clo[cnt] = 'R' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
            }
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j , 0) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdlib>
#include<queue>
using namespace std ;
const int MAXN = 605 ;
char map[MAXN][MAXN] ;
int vis[MAXN][MAXN] ;
int n , m ;
int X[4] = {0 , 0 , 1 , -1} ;
int Y[4] = {1 , -1 , 0 , 0} ;
char clo[MAXN * MAXN] ;
int zx[MAXN * MAXN] ;
int zy[MAXN * MAXN] ;
int cango(int x , int y)
{
    if( x >= 1 && x <= n && y >= 1 && y <= m && !vis[x][y] && map[x][y] == '.')
        return 1 ;
    return 0 ;
}
int cnt ;
void dfs(int x , int y , int xu)
{
    vis[x][y] = 1 ;
    clo[cnt] = 'B' ;
    zx[cnt] = x ;
    zy[cnt] = y ;
    cnt ++ ;
    int k ;
    for(k = 0 ; k < 4 ; k ++)
    {
        int tx = x + X[k] ;
        int ty = y + Y[k] ;
        if(cango(tx , ty))
        {
            vis[tx][ty] = 1 ;
            dfs(tx , ty , xu + 1) ;
            if(xu + 1 != 0)
            {
                clo[cnt] = 'D' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
                clo[cnt] = 'R' ;
                zx[cnt] = tx ;
                zy[cnt] = ty ;
                cnt ++ ;
            }
        }
    }
}
int main()
{
    while (scanf("%d%d" , &n , &m) != EOF)
    {
        memset(map , 0 , sizeof(map)) ;
        memset(vis , 0 , sizeof(vis)) ;
        memset(clo , 0 , sizeof(clo)) ;
        memset(zx , 0 , sizeof(zx)) ;
        memset(zy , 0 , sizeof(zy)) ;
        int i , j ;
        cnt = 0 ;
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                cin >> map[i][j] ;
            }
        }
        for(i = 1 ; i <= n ; i ++)
        {
            for(j = 1 ; j <= m ; j ++)
            {
                if(map[i][j] == '.' && !vis[i][j])
                {
                    dfs(i , j , 0) ;
                }
            }
        }
        printf("%d\n" , cnt) ;
        for(i = 0 ; i < cnt ; i ++)
        {
            printf("%c %d %d\n" , clo[i] , zx[i] , zy[i]) ;
        }
    }
    return 0 ;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> que,ans;
int n,m;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void bfs(int x,int y)
{
    while (que.size()) que.pop();
    struct note s;
    s.x=x;s.y=y;
    que.push(s);
    while (que.size()) {
        struct note cur,next;
        cur=que.front();
        que.pop();
        for (int i=0;i<4;i++) {
            int dx=cur.x+Next[i][0];
            int dy=cur.y+Next[i][1];
            if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.') {
                next.x=dx;next.y=dy;
                ans.push(cur);
                mmap[cur.x][cur.y]='#';
                que.push(next);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  ans.push(cur);
                }
            }
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    bfs(i,j);
                }
            }
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> que,ans,res;
int n,m;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void bfs(int x,int y)
{
    while (que.size()) que.pop();
    struct note s;
    s.x=x;s.y=y;
    que.push(s);
    while (que.size()) {
        struct note cur,next;
        cur=que.front();
        que.pop();
        for (int i=0;i<4;i++) {
            int dx=cur.x+Next[i][0];
            int dy=cur.y+Next[i][1];
            if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.') {
                next.x=dx;next.y=dy;
                ans.push(cur);
                mmap[cur.x][cur.y]='#';
                que.push(next);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  res.push(cur);
                }
            }
        }

        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    bfs(i,j);
                }
            }
        }
        printf("%d\n",res.size()+ans.size());
        while (res.size()) {
            struct note cur=res.front();
            res.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> que,ans,res;
int n,m,step;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void bfs(int x,int y)
{
    while (que.size()) que.pop();
    struct note s;
    s.x=x;s.y=y;
    que.push(s);
    while (que.size()) {
        struct note cur,next;
        cur=que.front();
        que.pop();
        for (int i=0;i<4;i++) {
            int dx=cur.x+Next[i][0];
            int dy=cur.y+Next[i][1];
            if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.') {
                next.x=dx;next.y=dy;
                ans.push(cur);
                mmap[cur.x][cur.y]='#';
                que.push(next);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  res.push(cur);
                }
            }
        }
        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    bfs(i,j);
                }
            }
        }
        step=res.size()+ans.size();
        printf("%d\n",step+2);
        while (res.size()) {
            struct note cur=res.front();
            res.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> res;
stack<struct note> ans;
int n,m,step;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void dfs(int x,int y)
{
    if (step) step=0;
    else {
        struct note cur;
        cur.x=x;cur.y=y;
        ans.push(cur);
    }
    mmap[x][y]='#';
    for (int i=0;i<4;i++) {
        int dx=x+Next[i][0];
        int dy=y+Next[i][1];
        if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.')
            dfs(dx,dy);
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  res.push(cur);
                }
            }
        }
        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    step=1;
                    dfs(i,j);
                }
            }
        }
        step=res.size()+ans.size()*2;
        printf("%d\n",step);
        while (res.size()) {
            struct note cur=res.front();
            res.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        while (ans.size()) {
            struct note cur=ans.top();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 505;
char g[N][N];
stack<pair<int, int> > s;
int x[] = { -1, 1, 0, 0};
int y[] = {0, 0, -1, 1};
int n, m, a, b, cnt, is_first;

int dfs(int i, int j)
{
    int r, c;
    if(is_first) is_first = 0;
    else s.push(make_pair(i, j));
    g[i][j] = 'R', cnt += 3;
    for(int k = 0; k < 4; ++k)
    {
        r = i + x[k], c = j + y[k];
        if(g[r][c] == '.') dfs(r, c);
    }
}

int main()
{
    while(~scanf("%d%d", &n, &m))
    {
        cnt = 0;
        for(int i = 1; i <= n; ++i)
            scanf("%s", g[i] + 1);
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
                if(g[i][j] == '.')  is_first = 1, cnt -= 2, dfs(i, j);
        printf("%d\n", cnt);
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
                if(g[i][j] != '#') printf("B %d %d\n", i, j);

        while(!s.empty())
        {
            a = s.top().first, b = s.top().second;
            printf("D %d %d\nR %d %d\n", a, b, a, b);
            s.pop();
        }
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;

const int maxn=500+10;
struct note
{
    int x,y;
};
queue<struct note> que,ans,res;
int n,m,step;
char mmap[maxn][maxn];
int Next[4][2]={{-1,0},{1,0},{0,-1},{0,1}};

void bfs(int x,int y)
{
    while (que.size()) que.pop();
    struct note s;
    s.x=x;s.y=y;
    que.push(s);
    while (que.size()) {
        struct note cur,next;
        cur=que.front();
        que.pop();
        for (int i=0;i<4;i++) {
            int dx=cur.x+Next[i][0];
            int dy=cur.y+Next[i][1];
            if (dx>=1&&dx<=n&&dy>=1&&dy<=m&&mmap[dx][dy]=='.') {
                next.x=dx;next.y=dy;
                ans.push(cur);
                mmap[cur.x][cur.y]='#';
                que.push(next);
            }
        }
    }
}
int main()
{
    while (scanf("%d%d",&n,&m)!=EOF) {
        for (int i=1;i<=n;i++) {
            for (int j=1;j<=m;j++) {
                cin>>mmap[i][j];
                if (mmap[i][j]=='.') {
                  struct note cur;
                  cur.x=i;cur.y=j;
                  res.push(cur);
                }
            }
        }
        for (int i=n;i>=1;i--) {
            for (int j=m;j>=1;j--) {
                if (mmap[i][j]=='.') {
                    bfs(i,j);
                }
            }
        }
        step=res.size()+ans.size()*2;
        printf("%d\n",step);
        while (res.size()) {
            struct note cur=res.front();
            res.pop();
            printf("B %d %d\n",cur.x,cur.y);
        }
        while (ans.size()) {
            struct note cur=ans.front();
            ans.pop();
            printf("D %d %d\nR %d %d\n",cur.x,cur.y,cur.x,cur.y);
        }
    }
    return 0;
}