#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

/*Macros para mayor facilidad*/
#define gl(cad) getline(cin,cad)
#define debug(X) cout<<#X<<" = "<<X<<endl
#define forn(X,i) for(int i=0; i<X;i++)
#define sz(cad) (int) cad.size()
#define str(cad) (int) strlen(cad)

using namespace std;

typedef vector<int> veci;
typedef vector<int,int> vecii;
typedef long long ll;

int main(){
	ll n;
	cin>>n;
	ll num[n-1];
	bool ans[n-1];
	for(int i=0;i<n-1;i++){
		ans[i]==false;
	}
	for(int i=1;i<n;i++){
		cin>>num[i];
		ans[num[i]]=true;
	}
	for(int i=1;i<=n;i++){
		if(!ans[i]){
			cout<<i;
			return 0;
		}
	}
	//system("PAUSE");system("cls");main();
	return 0;
}


#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>

/*Macros para mayor facilidad*/
#define gl(cad) getline(cin,cad)
#define debug(X) cout<<#X<<" = "<<X<<endl
#define forn(X,i) for(int i=0; i<X;i++)
#define sz(cad) (int) cad.size()
#define str(cad) (int) strlen(cad)

using namespace std;

typedef vector<int> veci;
typedef vector<int,int> vecii;
typedef long long ll;

int main(){
	ll n;
	cin>>n;
	ll num[n-1];
	bool ans[n-1];
	memset(num,0,n-1);
	for(int i=1;i<n;i++){
		cin>>num[i];
		ans[num[i]]=true;
	}
	for(int i=1;i<=n;i++){
		if(!ans[i]){
			cout<<i;
			return 0;
		}
	}
	//system("PAUSE");system("cls");main();
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
        break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x,a=0;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
          a=1;
        }
    }
    if ((a==0)&& (ep[0]==1))
    cout << ep [x-2]+1;
    else
        cout << ep[0];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=0;i<x;i++)
    {
        if (ep[i]-ep[i-1]==2)
            cout << i+1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{

    int x;
    int ep [x];
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
        break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x,a=0;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
        break;
          a=1;
        }
    }
    if (a==0)
    cout << ep [x-2]+1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x,a=0;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
          a=1;
        }
    }
    if ((a==0)&& (ep[0]==1))
    cout << ep [x-2]+1;
    else if (a==0)
        cout << 1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [100000];
    int x,a=0;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
          a=1;
        }
    }
    if ((a==0)&& (ep[0]==1))
    cout << ep [x-2]+1;
    else if (a==0)
        cout << 1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x,a=0;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
          a=1;
        }
    }
    if (a==0)
    cout << ep [x-2]+1;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=x-1;i>=0;i++)
    {
        if (ep[i]-ep[i-1]==2)
            cout << i+1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2)
            cout << i+1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x-1;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x-1);
    for (int i=x-2;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2){
            cout << ep[i]-1;
        break;
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int ep [10000];
    int x;
    cin >> x;
    for (int i =0; i<x;i++)
    {
        cin >> ep[i];
    }
    sort (ep,ep+x);
    for (int i=x-1;i>=0;i--)
    {
        if (ep[i]-ep[i-1]==2)
            cout << i+1;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	bool a[100005]={0};
	int n,c;
	cin>>n;
	for(int s=1;s<n;s++)
	{
		cin>>c;
		a[c]=1;
	}
	for(int y=1;y<=n;y++)
		if(a[y]==0)
			cout<<y;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[100001];
int main(){
    cin>>n;
    for(int i=1;i<n;i++)
		cin>>a[i];
    sort(a+1,a+n);
    for(int i=1;i<=n;i++)
        if(a[i]!=i) {
            cout<<i<<endl;
            break;
        }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,a[100005],p[100005];
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		cin>>a[i];
		p[a[i]]=1;
	}

	for(int i=1;i<=n;i++)
		if(!p[i])
			cout<<i;
	return 0;
}


#include <cstdio>
#include <cmath>
using namespace std;
int t;

int main()

{
	int n;
	bool a[10005] = {0};
	scanf("%d", &n);
	for (int i = 1; i <= n - 1; i++)
	{
		scanf("%d", &t);
		a[t] = true;
	}

	for (int i = 1; i <= n; i ++)
		{
			if(a[i]);
			else{
					printf("%d", i);
					break;
				}
		}
	return 0;
}


#include<bits/stdc++.h>
bool vis[100005];
int n;
int main()
{
	int i,k;
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d",&k);
		vis[k]=1;
	}
	for (i=1;i<=n;i++)
	if (!vis[i]){printf("%d",i);return 0;}
	return 0;
}


//zdj
#include<cstdio>
#define S 1<<23
int n;
bool a[100010];
char fd[S],*p(fd-1);
inline int read()
{
	while(*++p<45);
	int x(*p&15);
	while(*++p>45)
		x=(x<<1)+(x<<3)+(*p&15);
	return x;
}
signed main()
{
	fread(fd,1,S,stdin),n=read();
	while(--n)
		a[read()]=1;
	while(++n)
		if(!a[n])
			return printf("%d\n",n),0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int n,a,ans;

int mian(){
	scanf("%d",&n);
	for(int i=1;i<=n-1;++i){
		scanf("%d",&a);
		ans+=a;
	}
	ans=(n+1)*n/2-ans;
	printf("%d",ans);
	return 0;
}


#include<cstdio>
using namespace std;
bool b[100010],n;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++)
	{
		int a;
		scanf("%d",&a);
		b[a]=true;
	}
	for (int i=1;i<=n;i++)
	{
		if (!b[i])
		{
			printf("%d",i);
			return 0;
		}
	}
}


#include<bits/stdc++.h>
using namespace std;

int box[100000005];

int main()
{
	int n, x;
	scanf("%d", &n);
	for(int i = 1; i < n; i++)
	{
		scanf("%d", &x);
		box[x]++;
	}
	for(int i = 1; i <= n; i++)
	{
		if(box[i] == 0)
		{
			printf("%d", i);
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,x;
int a[100005]={0};
int main()
{
	 scanf("%d",&n);
	 for(int i=1;i<n;i++)
	 {
	 	 scanf("%d",&x);
	 	 a[x]=1;
	 }
	 for(int i=1;i<=n;i++)
	 {
	 	 if(a[i]==0)
	 	 {
	 	 	 printf("%d\n",i);
	 	 	 return 0;
		 }
	 }
	 return 0;
}


#include<iostream>
using namespace std;
int n,f[1<<17];
int main()
{
    cin>>n;
    for(int i=1,j;i<=n-1;i++)
    {
        cin>>j;
        f[j]++;
    }
    for(int i=1;i<=n;i++)
        if(!f[i])
        {
            cout<<i;
            break;
        }
    return 0;
}


#include<bits/stdc++.h>
long long i,n,a,ans;
int main(){
    scanf("%lld",&n);
    for(register int i=1;i<n;++i)scanf("%lld",&a),ans+=a;
    printf("%lld",(1+n)*n/2-ans);
}


#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
long long n;
int a[100000],shu;
int main()
{
    cin>>n;
    for(int i=1; i<=n-1; i++)
    {
    	cin>>shu;
    	a[shu]++;
    }
    for(int i=1; i<=n; i++)
    {
    	if(a[i]==0)
    	{
    		cout<<i;
    		return 0;
    	}
    }
    return 0;
}


#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;

const int FFF=6666;

int n;
int a[FFF];

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n-1;++i)
	{
		cin>>a[i];
	}
	sort(a,a+n-1);
	for(int i=1;i<n-1;++i)
	{
		if(a[i]-a[i-1]!=1)
		{
			cout<<a[i]-1<<endl;
			return 0;
		}
	}
}


#include <cstdio>
#include <cmath>
using namespace std;
bool a[10001];
int main()
{
	int n,m;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d",&m);
		a[m]=1;
	}
	for(int i=1;i<=n;i++)
	{
		if(!a[i])
		printf("%d",i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;bool a[100001];
    cin>>n;
    for(int i=1;i<=n-1;i++)
    {cin>>k;a[k]=true;}
    for(int i=1;i<=n;i++)
    if(!a[i]){cout<<i;break;}
}


#include<bits/stdc++.h>
using namespace std;
int n,a,b[1000010];
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
		cin>>a,b[a]=1;
	for(int i=1;i<=n;i++)
	{
		if(!b[i])
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,s=0;
    cin>>n;
    for(long long i=1;i<=n;i++){
        long long a;
        cin>>a;
        s+=a;
    }
    cout<<((1+n)*n/2)-s;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100010],b[100010];
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a[i];
		b[a[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(b[i]==0)cout<<i;
	}
	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;
const int MAXN = 100010;

bool a[MAXN];

int main() {
	int n, res = 1; scanf("%d", &n);
	while (--n) {
		int x; scanf("%d", &x);
		a[x] = true; while (a[res]) ++res;
	}
	printf("%d\n", res);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,a,t,k;
int main()
{
	cin>>n;
	t=n*(n+1)/2;
	for(int i=1;i<=n-1;i++)
	{
		cin>>a;
		k+=a;
	}
	cout<<t-k<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}
//
template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 1e5;
int n;
bool m[MAXN + 5];

int main() {
	read(n);
	for (int x, i = 1; i < n; ++i) {
		read(x);
		m[x] = 1;
	}
	for (int i = 1; i <= n; ++i)
		if (!m[i]) {
			write(i);
			putchar('\n');
			break;
		}
	return 0;
}


#include<iostream>
using namespace std;
int n;
int a[100005];
int main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    for(int i=1;i<=n;i++)
        if(!a[i])
        {
            cout<<i<<endl;
            break;
        }
    return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=100000+7;
bool vis[MAXN];
int n;
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x; scanf("%d",&x);
		vis[x]=1;
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
#include<ctime>
#include<algorithm>
using namespace std;

int main()
{
int a,b,c[100001]={0};
cin>>a;
for(int i=1;i<a;i++)
{
	scanf("%d",&b);
	c[b]=1;
}
int i=0;
while(1)
{
	i++;
	if(c[i]==0)
	{
		printf("%d",i);
		break;
	}
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool a[n+5];
int main(){
	int n,m;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		scanf("%d",&m);
		a[m]=1;
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=0)
		printf("%d",i);
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
bool pd[100001];
int main(){
    cin>>n;
    int x;
    for(int i=1;i<n;++i)
	{
        cin>>x;
        pd[x]=1;
    }
    for(int i=1;i<=n;++i)
    if(!pd[i]){cout<<i<<endl;break;}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
bool tong[100001];
int main()
{
    int n;
    cin>>n;
    int tmp;
    for(int i=1;i<n;i++)
    {
        cin>>tmp;
        tong[tmp]=1;
    }
    for(int i=1;i<=n;i++)
    {
        if(tong[i]==0)
        {
            cout<<i;
            return 0;
        }
    }
}


#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a;ll ans;
int main(){
	in(n);
	ans=(1ll)*n*(n+1)/2;
	for(int i=1;i<=n;i++){
		in(a);ans-=(1ll)*a;
	}
	printf("%lld\n",ans);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,x,ans;
int main(void){
    scanf("%lld",&n);
    ans=(1+n)*n/2;
    for(int i=1;i<n;i++){
        scanf("%lld",&x);
        ans-=x;
    }
    printf("%lld",ans);
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#define MAX 100005
using namespace std;
int a[MAX];
bool q[MAX];
int main()
{
	memset(q,false,sizeof(q));
	int n,i;
	cin>>n;
	for(i=0;i<n-1;i++)
	{
		cin>>a[i];
		q[a[i]]=true;
	}
	for(i=1;i<=n;i++)
	{
		if (q[i]==false)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int a,n,i,a1[100000];
int main()
{
	cin>>n;
	for(i=1;i<=n-1;i++)
	{
		cin>>a;
		a1[a]++;
	}
	for(i=1;i<=n;i++) if(a1[i]==0) cout<<i;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long n,x,ans;
int main()
{
    cin>>n;
    ans=(1+n)*n/2;
    for(int i=1;i<n;i++)
	{
        cin>>x;
        ans-=x;
    }
    cout<<ans;
    return 0;
}


#include<iostream>
#include<set>
using namespace std;
set<int> S;
int n;
int main()
{
	cin >> n;
	for(int i=1;i<=n-1;i++)
	{
		int x;
		cin >> x;
		S.insert(x);
	}
	for(int i=1;i<=n;i++)
		if(!S.count(i))
		{
			cout << i << endl;
			break;
		}
	return 0;
}


#include<iostream>
using namespace std;
int a[100001],n,i,m;
int main()
{
	cin>>n;
	for (i=1;i<=n-1;i++)
	{
		cin>>m;
		a[m]=1;
	}
	for (i=1;i<=n;i++)
	  if (a[i]!=1) cout<<i<<endl;
	return 0;
}


#include<cstdio>
using namespace std;

int main()
{
	int a[10005] = {0};
	int n, t;
	scanf("%d", &n);
	for(int i = 0; i < n - 1; i++)
	{
		scanf("%d", &t);
		a[t] = 1;
	}

	for(int i = 1; i <= n; i++)
	{
		if(a[i] == 0)
		{
			printf("%d", i);
			break;
		}
	}

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	long long ans=n*(long long)(n+1)/2;
	int a;
	while(--n)
	{
		scanf("%d",&a);
		ans-=a;
	}
	printf("%d\n",int(ans));
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[555][555];
vector< vector<int> > g(555);
int visited[100010];
int n,m;
int h;
vector< pair<char,II> > sol;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	sol.PB(MP('B',MP((s/m)+1,(s%m)+1)));
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		sol.PB(MP('D',MP((s/m)+1,(s%m)+1)));
		sol.PB(MP('R',MP((s/m)+1,(s%m)+1)));
	}
}
int main()
{
	int s,f=1,t,ans;
	SET(visited,0);
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
			}
			if(a[i][j]=='#')
				visited[i*m+j]=1;
		}
	}
	while(1)
	{
		h=s;
		dfs_tree(s,-1);
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		if(f) break;
	}
	cout << sol.size() << endl;
	for(int i=0;i<sol.size();i++)
		cout << sol[i].first <<  " " << sol[i].second.first << " " << sol[i].second.second << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[1000][1000];
vector< vector<int> > g(300010);
int visited[300010];
int n,m;
int h;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	cout << 'B' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		cout << 'D' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
		cout << 'R' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
	}
}
int main()
{
	int s,f=1,t,count=0,flag=0;
	for(int i=0;i<(n*m);i++)
		visited[i]=0;
	cin >> n >> m;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
			}
			if(a[i][j]=='#')
				count++;
		}
	}
	int component[300010];
	vector< vector<int> > components(300010);
	int iter=1;
	while(1)
	{
		dfs(s);
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
			}
			if(visited[i] && !component[i])
			{
				component[i]=iter;
				components[iter].PB(i);
			}
		}
		if(f) break;
		iter++;
	}
	LL ans=0;
	for(LL i=1;i<=iter;i++)
		ans+=(components[i].size()-1)*3+1;
	ans-=count;
	cout << ans << endl;
	for(LL i=0;i<(n*m);i++)
	{
		if(a[i/m][i%m]=='#')
			visited[i]=1;
		else
			visited[i]=0;
	}
	while(1)
	{
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		h=s;
		if(f) break;
		dfs_tree(s,-1);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[555][555];
vector< vector<int> > g(555);
int visited[555];
int n,m;
int h;
int component[555];
vector< pair<char,II> > sol;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	sol.PB(MP('B',MP((s/m)+1,(s%m)+1)));
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		sol.PB(MP('D',MP((s/m)+1,(s%m)+1)));
		sol.PB(MP('R',MP((s/m)+1,(s%m)+1)));
	}
}
int main()
{
	int s,f=1,t,ans;
	SET(visited,0);
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	for(int i=0;i<(n*m);i++)
		component[i]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
			}
			if(a[i][j]=='#')
				visited[i*m+j]=1;
		}
	}
	while(1)
	{
		h=s;
		dfs_tree(s,-1);
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		if(f) break;
	}
	cout << sol.size() << endl;
	for(int i=0;i<sol.size();i++)
		cout << sol[i].first <<  " " << sol[i].second.first << " " << sol[i].second.second << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[555][555];
vector< vector<int> > g(300010);
int visited[300010];
int n,m;
int h;
vector< pair<char,II> > sol;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	sol.PB(MP('B',MP((s/m)+1,(s%m)+1)));
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		sol.PB(MP('D',MP((s/m)+1,(s%m)+1)));
		sol.PB(MP('R',MP((s/m)+1,(s%m)+1)));
	}
}
int main()
{
	int s,f=1,t,ans;
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
				visited[i*m+j]=0;
			}
			if(a[i][j]=='#')
				visited[i*m+j]=1;
		}
	}
	while(1)
	{
		h=s;
		dfs_tree(s,-1);
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		if(f) break;
	}
	cout << sol.size() << endl;
	for(LL i=0;i<sol.size();i++)
		cout << sol[i].first <<  " " << sol[i].second.first << " " << sol[i].second.second << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
struct x
{
	char c;
	int a;
	int b;
};
char a[555][555];
int visited[555][555];
int n,m;
int ii,jj;
vector<x> sol;
void dfs1(int i,int j)
{
	visited[i][j]=1;
	sol.PB((x){'B',i+1,j+1});
	if(i>0 && a[i-1][j]=='.' && !visited[i-1][j])
		dfs1(i-1,j);
	if(i<n-1 && a[i+1][j]=='.' && !visited[i+1][j])
		dfs1(i+1,j);
	if(j>0 && a[i][j-1]=='.' && !visited[i][j-1])
		dfs1(i,j-1);
	if(j<m-1 && a[i][j+1]=='.' && !visited[i][j+1])
		dfs1(i,j+1);
	if(i!=ii || j!=jj)
	{
		sol.PB((x){'D',i+1,j+1});
		sol.PB((x){'R',i+1,j+1});
	}
}
int main()
{
	int s,f=1,t,ans,start=0;
	cin >> n >> m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin >> a[i][j];
			visited[i][j]=0;
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.' && !visited[i][j])
			{
				ii=i;
				jj=j;
				dfs1(i,j);
			}
		}
	}
	cout << sol.size() << endl;
	for(LL i=0;i<sol.size();i++)
		cout << sol[i].c <<  " " << sol[i].a << " " << sol[i].b << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[1000][1000];
vector< vector<int> > g(100010);
int visited[100010];
int n,m;
int h;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	cout << 'B' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		cout << 'D' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
		cout << 'R' << " " << (s/m)+1 << " " << (s%m)+1 << endl;
	}
}
int main()
{
	int s,f=1,t,count=0;
	for(int i=0;i<(n*m);i++)
		visited[i]=0;
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
			}
			if(a[i][j]=='#')
				count++;
		}
	}
	int component[100010];
	vector< vector<int> > components(100010);
	int iter=1;
	while(1)
	{
		dfs(s);
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
			}
			if(visited[i] && !component[i])
			{
				component[i]=iter;
				components[iter].PB(i);
			}
		}
		if(f) break;
		iter++;
	}
	LL ans=0;
	for(LL i=1;i<=iter;i++)
		ans+=(components[i].size()-1)*3+1;
	ans-=count;
	cout << ans << endl;
	for(LL i=0;i<(n*m);i++)
	{
		if(a[i/m][i%m]=='#')
			visited[i]=1;
		else
			visited[i]=0;
	}
	while(1)
	{
		f=1;
		for(int i=0;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		h=s;
		if(f) break;
		dfs_tree(s,-1);
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
char a[555][555];
vector< vector<int> > g(300010);
int visited[300010];
int n,m;
int h;
vector< pair<char,II> > sol;
void dfs(int s)
{
	visited[s]=1;
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u])
			dfs(u);
	}
}
void dfs_tree(int s,int v)
{
	visited[s]=1;
	sol.PB(MP('B',MP((s/m)+1,(s%m)+1)));
	for(int i=0;i<g[s].size();i++)
	{
		int u=g[s][i];
		if(!visited[u] && u!=v)
			dfs_tree(u,s);
	}
	if(s!=h)
	{
		sol.PB(MP('D',MP((s/m)+1,(s%m)+1)));
		sol.PB(MP('R',MP((s/m)+1,(s%m)+1)));
	}
}
int main()
{
	int s,f=1,t,ans,start=0;
	cin >> n >> m;
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			cin >> a[i][j];
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(a[i][j]=='.')
			{
				if(i>0 && a[i-1][j]=='.')
					g[i*m+j].PB((i-1)*m+j);
				if(i<n-1 && a[i+1][j]=='.')
					g[i*m+j].PB((i+1)*m+j);
				if(j>0 && a[i][j-1]=='.')
					g[i*m+j].PB(i*m+j-1);
				if(j<m-1 && a[i][j+1]=='.')
					g[i*m+j].PB(i*m+j+1);
				s=i*m+j;
				visited[i*m+j]=0;
			}
			if(a[i][j]=='#')
				visited[i*m+j]=1;
		}
	}
	while(1)
	{
		f=1;
		for(int i=start;i<(n*m);i++)
		{
			if(!visited[i])
			{
				f=0;
				s=i;
				break;
			}
		}
		h=s;
		if(f) break;
		dfs_tree(s,-1);
		start=s+1;
	}
	cout << sol.size() << endl;
	for(LL i=0;i<sol.size();i++)
		cout << sol[i].first <<  " " << sol[i].second.first << " " << sol[i].second.second << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<vector<int> > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || B[x][y]=='#' || vis[x][y]==1)
		return ;
	cnt++;
	vis[x][y]=1;
	vector<int> a;
	a.push_back(0);
	a.push_back(x+1);
	a.push_back(y+1);
	ans.push_back(a);
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(cnt>1 && d!=-1)
	{
		a.clear();
		a.push_back(2);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
		a.clear();
		a.push_back(1);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
		for(j=0;j<m;j++)
		{
			vis[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				cnt=0;
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		if(ans[i][0]==0)
		{
			cout<<"B ";
		}
		else if(ans[i][0]==1)
		{
			cout<<"R ";
		}
		else
		{
			cout<<"D ";
		}
		cout<<ans[i][1]<<" "<<ans[i][2]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<pair<char, pair<int,int> >  > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || B[x][y]=='#' || vis[x][y]==1)
		return ;
	cnt++;
	vis[x][y]=1;
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(cnt>1 && d!=-1)
	{
		ans.push_back(make_pair('D',make_pair(x+1,y+1)));
		ans.push_back(make_pair('R',make_pair(x+1,y+1)));

	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
		for(j=0;j<m;j++)
		{
			vis[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(B[i][j]=='.')
				ans.push_back(make_pair('B',make_pair(i+1,j+1)));
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				cnt=0;
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<string.h>
#include<cstring>
#include<stack>
#include<queue>
#include<cassert>
#include<cmath>
using namespace std;

#define LL long long int
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define INF 1000000000
#define debug(args...) do {cerr << #args << ": "; dbg,args; cerr << endl;} while(0)

string a[700];
int vis[600][600];
int dx[] = {-1,0,0,1};
int dy[] = {0,1,-1,0};
int n,m;
vector<pair<char,PII> > ans;
int dfs(int cx,int cy,int fl = 0){
    if(cx < 0 || cy < 0 || cx >=n || cy >= m)
        return 0;
    if(vis[cx][cy])
        return 0;
    vis[cx][cy] = 1;

    for(int i=0;i<4;i++)
        dfs(cx +dx[i],cy + dy[i]);
    if(fl == 0){
        ans.PB(MP('D',MP(1+cx,1+cy)));
        ans.PB(MP('R',MP(1+cx,1+cy)));
    }
}

int main(){
    int i,j;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(a[i][j] == '.')
                ans.PB(MP('B',MP(1+i,1+j)));
            else
                vis[i][j]= 1;
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            if(vis[i][j] == 0){
                dfs(i,j,1);
            }
        }
    }
    cout<<ans.size()<<endl;
    for(i=0;i<ans.size();i++)
        printf("%c %d %d\n",ans[i].first,ans[i].second.first,ans[i].second.second);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<vector<int> > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || B[x][y]=='#' || vis[x][y]==1)
		return ;
	cnt++;
	vis[x][y]=1;
	vector<int> a;
	a.push_back(0);
	a.push_back(x+1);
	a.push_back(y+1);
	ans.push_back(a);
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(cnt>1 && d!=-1)
	{
		a.clear();
		a.push_back(2);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
		a.clear();
		a.push_back(1);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
		for(j=0;j<m;j++)
		{
			vis[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				cnt=0;
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		if(ans[i][0]==0)
		{
			cout<<"B ";
		}
		else if(ans[i][0]==1)
		{
			cout<<"R ";
		}
		else
		{
			cout<<"D ";
		}
		cout<<ans[i][1]<<" "<<ans[i][2]<<endl;
	}
	return 0;
}#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<vector<int> > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || B[x][y]=='#' || vis[x][y]==1)
		return ;
	cnt++;
	vis[x][y]=1;
	vector<int> a;
	a.push_back(0);
	a.push_back(x+1);
	a.push_back(y+1);
	ans.push_back(a);
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(cnt>1 && d!=-1)
	{
		a.clear();
		a.push_back(2);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
		a.clear();
		a.push_back(1);
		a.push_back(x+1);
		a.push_back(y+1);
		ans.push_back(a);
	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
		for(j=0;j<m;j++)
		{
			vis[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				cnt=0;
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		if(ans[i][0]==0)
		{
			cout<<"B ";
		}
		else if(ans[i][0]==1)
		{
			cout<<"R ";
		}
		else
		{
			cout<<"D ";
		}
		cout<<ans[i][1]<<" "<<ans[i][2]<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<pair<char, pair<int,int> >  > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || vis[x][y]==1)
		return ;
	vis[x][y]=1;
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(d!=-1)
	{
		ans.push_back(make_pair('D',make_pair(x+1,y+1)));
		ans.push_back(make_pair('R',make_pair(x+1,y+1)));

	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(B[i][j]=='.')
				ans.push_back(make_pair('B',make_pair(i+1,j+1)));
			else
				vis[i][j]=1;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,cnt;

vector<string> B(501);
vector<pair<char, pair<int,int> >  > ans;
int vis[501][501];
void dfs(int x,int y,int d)
{
	if(x<0 || y<0 || x>=n || y>=m || vis[x][y]==1)
		return ;
	vis[x][y]=1;
	dfs(x-1,y,1);
	dfs(x+1,y,1);
	dfs(x,y-1,1);
	dfs(x,y+1,1);
	if(d!=-1)
	{
		ans.push_back(make_pair('D',make_pair(x+1,y+1)));
		ans.push_back(make_pair('R',make_pair(x+1,y+1)));

	}

}
int main()
{
	int i,j;
	cin>>n>>m;
	for(i=0;i<n;i++)
	{
		cin>>B[i];
		for(j=0;j<m;j++)
		{
			vis[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(B[i][j]=='.')
				ans.push_back(make_pair('B',make_pair(i+1,j+1)));
			else
				vis[i][j]=1;
		}
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(!vis[i][j])
			{
				dfs(i,j,-1);
			}
		}
	}
	cout<<ans.size()<<endl;
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i].first<<" "<<ans[i].second.first<<" "<<ans[i].second.second<<endl;
	}
	return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[500][500];
int used[500][500];

int dfs(int i,int j,int f) {
    int x,y;
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+(l==0)-(l==1);
                  y=j+(l==2)-(l==3);
                  if(x<0||x>n-1) continue;
                  if(y<0||y>m-1) continue;
                  if(used[x][y]==0&&g[x][y]!='#') dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    cin>>g[i][j];
                    used[i][j]=0;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if((g[i][j]=='.')&&(used[i][j]==0)) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[505][505];
int used[505][505];
int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

int dfs(int i,int j,int f) {
    int x,y;
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+d[l][0]; y=j+d[l][1];
                  if(x<0||x>n-1) continue;
                  if(y<0||y>m-1) continue;
                  if(used[x][y]==0) dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    cin>>g[i][j];
                    if(g[i][j]=='.') used[i][j]=0;
                    else used[i][j]=1;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if(used[i][j]==0) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;

}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N = 505;
int num[N][N],len = 0,n,m;
char ch[N];
char ans[N*N*3][15];
void dfs(int x,int y,int flag){
    num[x][y] = 1;
    sprintf(ans[len], "%c %d %d",'B',x+1,y+1);
    len++;
    for(int i = 0; i < 4; i++){
        int nx = x + (i == 0) - (i == 1);
        int ny = y + (i == 2) - (i == 3);
        if(nx >= 0 && nx < n && ny >= 0 && ny < m && num[nx][ny] == 0)
            dfs(nx,ny,0);
    }
    if(!flag){
        sprintf(ans[len++], "%c %d %d",'D',x+1,y+1);
        sprintf(ans[len++], "%c %d %d",'R',x+1,y+1);
    }
}
int main(){
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> ch;
        for(int j = 0; j < m; j++)
            num[i][j] = ch[j] == '#';
    }
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++) if(!num[i][j]) dfs(i,j,1);
        cout<<len<<endl;
    for(int i = 0; i < len; i++)
        puts(ans[i]);
}


#include <iostream>
#include <cstdio>

using namespace std;

const int N=510;

int n,m,len=0;
char buffer[N*N*2][10];
char g[N];
int used[N][N];
//int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

void dfs(int i,int j,int f) {
    int x,y;
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+(l==0)-(l==1);
		          y=j+(l==2)-(l==3);
                  //x=i+d[l][0]; y=j+d[l][1];
                  if(x>=0 && x<n && y>=0 && y<m && used[x][y]==0) dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            cin>>g;
            for(int j=0;j<m;j++) {
                    used[i][j]=g[j]=='#';
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if(used[i][j]==0) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[500][500];
int used[500][500];

void dfs(int i,int j,int f) {
    int x,y;
    int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+d[l][0]; y=j+d[l][1];
                  if(x<0||x>n-1) continue;
                  if(y<0||y>m-1) continue;
                  if(used[x][y]==0&&g[x][y]!='#') dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    cin>>g[i][j];
                    used[i][j]=0;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if((g[i][j]=='.')&&(used[i][j]==0)) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;
}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[500][500];
int used[500][500];

int dfs(int i,int j,int f) {
    int x,y;
    int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+d[l][0]; y=j+d[l][1];
                  if(x<0||x>n-1) continue;
                  if(y<0||y>m-1) continue;
                  if(used[x][y]==0&&g[x][y]!='#') dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d",i+1,j+1);
              sprintf(buffer[len++],"R %d %d",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    cin>>g[i][j];
                    used[i][j]=0;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if((g[i][j]=='.')&&(used[i][j]==0)) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) puts(buffer[i]);
    return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[500][500];
int used[500][500];

int dfs(int i,int j,int f) {
    int x,y;
    int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+d[l][0]; y=j+d[l][1];
                  if(x<0||x>n-1) continue;
                  if(y<0||y>m-1) continue;
                  if(used[x][y]==0&&g[x][y]!='#') dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    cin>>g[i][j];
                    used[i][j]=0;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if((g[i][j]=='.')&&(used[i][j]==0)) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;

}


#include <iostream>
#include <cstdio>

using namespace std;

int n,m,len=0;
char buffer[250000*2][10];
char g[505];
int used[505][505];
int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

int dfs(int i,int j,int f) {
    int x,y;
    used[i][j]=1;
    sprintf(buffer[len++],"B %d %d\n",i+1,j+1);
    for(int l=0;l<4;l++) {
                  x=i+d[l][0]; y=j+d[l][1];
                  if(x>=0 && x<=n-1 && y>=0 && y<=m-1 && !used[x][y]) dfs(x,y,0);
            }
    if(f==0) {
              sprintf(buffer[len++],"D %d %d\n",i+1,j+1);
              sprintf(buffer[len++],"R %d %d\n",i+1,j+1);
             }
}

int main() {
    cin>>n>>m;
    for(int i=0;i<n;i++) {
            cin>>g;
            for(int j=0;j<m;j++) {
                    if(g[j]=='.') used[i][j]=0;
                    else used[i][j]=1;
                            }
                    }
    for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                    if(used[i][j]==0) dfs(i,j,1);
                                 }
                    }
    cout<<len<<endl;
    for(int i=0;i<len;i++) cout<<buffer[i];
    return 0;

}


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

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);
}

string toString (int a) {
    string result = "";
    while (a) {
        string c = "0";
        c[0] += a % 10;
        result = c + result,
        a /= 10;
    }
    return result;
}

int main () {
    int n, m; cin >> n >> m;
    graph.resize(n);
    char output[100];
    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] != '#') {
                sprintf(output, "B %d %d", i + 1, j + 1);
                result.push_back(string(output));
            }
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] == '.') {
                vector<Node> component;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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++) {
             sprintf(output, "D %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
             sprintf(output, "R %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


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

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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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);
         }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


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

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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>

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++) {
            string c1 = "1", c2 = "1";
            if (graph[i][j] != '#') {
                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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                sort(component.begin(), component.end(), comp);
                components.push_back(component);
            }
     for (int i = 0; i < components.size(); i++) {
         string c1 = "1", c2 = "1";
         for (int j = 0; j < components[i].size() - 1; j++) {
             c1[0] += components[i][j].x, c2[0] += components[i][j].y;
             result.push_back("D " + c1 + " " + c2);
             result.push_back("R " + c1 + " " + c2);
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


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

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];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] != '#')
                cout << "B " << i + 1 << " " << j + 1 << endl;
    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++)
             cout << "R " << components[i][j].x + 1 << " " <<
                     components[i][j].y + 1 << endl;
     return 0;

}


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

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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();cout << node.x << " " << node.y << " " << node.dist << endl;
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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<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("R " + c1 + " " + c2);
         }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


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

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);
}

string toString (int a) {
    string result = "";
    while (a) {
        string c = "0";
        c[0] += a % 10;
        result = c + result,
        a /= 10;
    }
    return result;
}

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 = toString(i + 1), c2 = toString(j + 1);
                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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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 =  toString(components[i][j].x + 1),
                    c2 =  toString(components[i][j].y + 1);
             result.push_back("D " + c1 + " " + c2);
             result.push_back("R " + c1 + " " + c2);
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stdio.h>

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);
}

string toString (int a) {
    string result = "";
    while (a) {
        string c = "0";
        c[0] += a % 10;
        result = c + result,
        a /= 10;
    }
    return result;
}

int main () {
    int n, m; cin >> n >> m;
    graph.resize(n);
    char output[100];
    for (int i = 0; i < n; i++)
    //    cin >> graph[i];
          graph[i] = string(m, '.');
    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] != '#') {
                sprintf(output, "B %d %d", i + 1, j + 1);
                result.push_back(string(output));
            }
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] == '.') {
                vector<Node> component;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    int x = queue.front().x, y = queue.front().y,
                            level = queue.front().dist;
                    component.push_back(queue.front());
                    queue.pop();
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                components.push_back(component);
            }
     for (int i = 0; i < components.size(); i++) {
         for (int j = components[i].size() - 1; j > 0; j--) {
             sprintf(output, "D %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
             sprintf(output, "R %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


#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];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] != '#')
                cout << "B " << i + 1 << " " << j + 1 << endl;
    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++)
             cout << "R " << components[i][j].x + 1 << " " <<
                     components[i][j].y + 1 << endl;
     return 0;

}


#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);
         }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stdio.h>

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);
}

string toString (int a) {
    string result = "";
    while (a) {
        string c = "0";
        c[0] += a % 10;
        result = c + result,
        a /= 10;
    }
    return result;
}

int main () {
    int n, m; cin >> n >> m;
    graph.resize(n);
    char output[100];
    for (int i = 0; i < n; i++)
        cin >> graph[i];
    //      graph[i] = string(m, '.');
    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] != '#') {
                sprintf(output, "B %d %d", i + 1, j + 1);
                result.push_back(string(output));
            }
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] == '.') {
                vector<Node> component;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    int x = queue.front().x, y = queue.front().y,
                            level = queue.front().dist;
                    component.push_back(queue.front());
                    queue.pop();
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                components.push_back(component);
            }
     for (int i = 0; i < components.size(); i++) {
         for (int j = components[i].size() - 1; j > 0; j--) {
             sprintf(output, "D %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
             sprintf(output, "R %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<stdio.h>

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);
}

string toString (int a) {
    string result = "";
    while (a) {
        string c = "0";
        c[0] += a % 10;
        result = c + result,
        a /= 10;
    }
    return result;
}

int main () {
    int n, m; cin >> n >> m;
    graph.resize(n);
    char output[100];
    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] != '#') {
                sprintf(output, "B %d %d", i + 1, j + 1);
                result.push_back(string(output));
            }
        }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (graph[i][j] == '.') {
                vector<Node> component;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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++) {
             sprintf(output, "D %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
             sprintf(output, "R %d %d", components[i][j].x + 1,
                             components[i][j].y + 1);
             result.push_back(string(output));
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}


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

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;
                queue<Node> queue;
                queue.push(Node(i, j, 0));
                graph[i][j] = '#';
                while (!queue.empty()) {
                    Node node = queue.front();
                    queue.pop();
                    int x = node.x, y = node.y, level = node.dist;
                    component.push_back(Node(x, y, level));
                    if (x > 0 && graph[x - 1][y] == '.')
                       graph[x - 1][y] = '#',
                       queue.push(Node(x - 1, y, level + 1));
                    if (x < n - 1 && graph[x + 1][y] == '.')
                       graph[x + 1][y] = '#',
                       queue.push(Node(x + 1, y, level + 1));
                    if (y > 0 && graph[x][y - 1] == '.')
                       graph[x][y - 1] = '#',
                       queue.push(Node(x, y - 1, level + 1));
                    if (y < m - 1 && graph[x][y + 1] == '.')
                       graph[x][y + 1] = '#',
                       queue.push(Node(x, y + 1, level + 1));
                }
                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";
             //cout << "DR " << components[i][j].x << endl;
             c1[0] += components[i][j].x, c2[0] += components[i][j].y;
             result.push_back("D " + c1 + " " + c2);
             result.push_back("R " + c1 + " " + c2);
         }
     }
     cout << result.size() << endl;
     for (int i = 0; i < result.size(); i++)
         cout << result[i] << endl;
     return 0;

}