#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define popcnt __builtin_popcount
#define MAX 200005
const ll MOD = 1000000007;
const ll INF = 1e18;

int parent[MAX];
int find_set(int v){
	if(parent[v] == v)
		return v;
	parent[v] = find_set(parent[v]);
	return parent[v];
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);

	ll n,m,k,q,w;
	cin>>n>>m>>k>>q;
	vector<ip> adj[n+1];

	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v>>w;
		adj[u].pb({v,w});
		adj[v].pb({u,w});
	}

	vector<ll> d(n+1,INF);
	vector<int> prev(n+1,-1);

	priority_queue<ip,vector<ip>,greater<ip> > pq;
	for(int i=1;i<=k;i++){
		d[i] = 0;
		pq.push({0,i});
		prev[i] = i;
	}

	int cnt = 0;
	vector<int> vis(n+1,0);
	while(!pq.empty()){
		ip z = pq.top();
		int idx = z.ss;
		pq.pop();

		if(vis[idx])
			continue;

		vis[idx] = 1;
		++cnt;
		if(cnt == n)
			break;

		for(ip next: adj[idx]){
			if(!vis[next.ff] && z.ff + next.ss < d[next.ff]){
				d[next.ff] = z.ff + next.ss;
				prev[next.ff] = prev[idx];
				pq.push({d[next.ff],next.ff});
			}
		}
	}

	vector<pair<ll,ip > > dist;

	for(int u=1;u<=n;u++){
		for(ip z: adj[u]){
			if(prev[u] != prev[z.ff]){
				dist.pb({z.ss+d[u]+d[z.ff],{prev[u],prev[z.ff]}});
			}
		}
	}

	sort(dist.begin(),dist.end());

	// cout<<"Dist:\n";
	// for(int i=0;i<dist.size();i++){
	// 	cout<< dist[i].ff << " " << dist[i].ss.ff << " " << dist[i].ss.ss << "\n";
	// }

	for(int i=1;i<=2*k;i++)
		parent[i] = i;

	ll res[2*k+1];
	ll up[2*k+1];
	int cur = k+1;
	for(int i=0;i<dist.size();i++){
		ll val = dist[i].ff;
		int u = find_set(dist[i].ss.ff);
		int v = find_set(dist[i].ss.ss);
		if(u == v)
			continue;
		parent[u] = parent[v] = cur;
		up[u] = up[v] = cur;
		res[cur] = val;
		++cur;
	}

	int f[cur][20];
	memset(f,0,sizeof(f));

	int dep[cur];
	dep[cur-1] = 0;

	for(int i=cur-2;i>=1;i--){
		dep[i] = dep[up[i]]+1;
		f[i][0] = up[i];
		for(int j=1;j<20;j++)
			f[i][j] = f[f[i][j-1]][j-1];
	}

	// for(int i=1;i<cur;i++){
	// 	cout<<"i="<<i<<": ";
	// 	for(int j=0;j<10;j++){
	// 		cout<<f[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	// }

	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;

		if(dep[a] > dep[b])
			swap(a,b);

		for(int j=19;j>=0;j--){
			if(dep[b]-dep[a] >= (1<<j))
				b = f[b][j];
		}

		for(int j=19;j>=0;j--){
			if(f[a][j] != f[b][j]){
				a = f[a][j];
				b = f[b][j];
			}
		}

		// cout<<"lca="<<f[a][0]<<"\n";

		cout<< res[f[a][0]] << "\n";
	}
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector < pair < long long , long long > > Next[200005];
vector < pair < long long , long long > > use[200005];
priority_queue < pair < long long , long long > , vector < pair < long long , long long > > , greater < pair < long long , long long > > > all;
priority_queue < pair < long long , pair < long long , long long > > , vector < pair < long long , pair < long long , long long > > > , greater < pair < long long , pair < long long , long long > > > > mst;
bool have[200005]={0};
long long con[200005];
long long Father[200005];
long long who[25][200005];
long long big[25][200005];
long long deg[200005];
pair < long long , pair < long long , long long > > t2;
pair < long long , long long > t;
long long Find(long long here)
{
    if(Father[here]==here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
void F(long long here,long long d)
{
    long long i,j;
    have[here]=1;
    deg[here]=d;
    for(auto i:use[here])
    {
        if(!have[i.first])
        {
            who[0][i.first]=here;
            big[0][i.first]=i.second;
            for(j=1;(1<<j)<=d;j++)
            {
                who[j][i.first]=who[j-1][who[j-1][i.first]];
                big[j][i.first]=max(big[j-1][i.first],big[j-1][who[j-1][i.first]]);
            }
            F(i.first,d+1);
        }
    }

}
long long LCA(long long a,long long b)
{
    long long i;
    if(a==b) return 0;
    if(deg[a]>deg[b]) for(i=20;i>=0;i--) if(deg[a]-(1<<i)>=deg[b]) return max(LCA(who[i][a],b),big[i][a]);
    if(deg[a]<deg[b]) for(i=20;i>=0;i--) if(deg[b]-(1<<i)>=deg[a]) return max(LCA(a,who[i][b]),big[i][b]);
    if(who[0][a]==who[0][b]) return max(big[0][a],big[0][b]);
    for(i=20;i>=0;i--) if((1<<i)<=max(deg[a],deg[b])&&who[i][a]!=who[i][b]) return max(max(big[i][a],big[i][b]),LCA(who[i][a],who[i][b]));
}
int main()
{
	long long N,M,K,Q,tt,i,a,b;
	scanf("%lld %lld %lld %lld",&N,&M,&K,&Q);
	for(i=0;i<M;i++)
	{
		scanf("%lld %lld %lld",&a,&b,&tt);
		Next[a].push_back(make_pair(b,tt));
		Next[b].push_back(make_pair(a,tt));
	}
	for(i=1;i<=K;i++) all.push(make_pair(0,i));
	while(!all.empty())
	{
		t=all.top();
		all.pop();
		//printf("bb %lld %lld\n",t.second,t.first);
		if(have[t.second]) continue;
		//printf("bb %lld %lld\n",t.second,t.first);
		have[t.second]=1;
		con[t.second]=t.first;
		for(auto i:Next[t.second]) all.push(make_pair(t.first+i.second,i.first));
	}
	for(i=1;i<=N;i++)
    {
        //printf("aa %lld %lld\n",i,con[i]);
        have[i]=0;
        Father[i]=i;
        for(auto &j:Next[i])
        {
            j.second+=con[i];
            j.second+=con[j.first];
            mst.push(make_pair(j.second,make_pair(i,j.first)));
        }
    }
    while(!mst.empty())
    {
        t2=mst.top();
        mst.pop();
        if(Find(t2.second.first)!=Find(t2.second.second))
        {
            //printf("cc %lld %lld %lld %lld %lld\n",t2.second.first,t2.second.second,t2.first,Find(t2.second.first),Find(t2.second.second));
            Father[Find(t2.second.first)]=Find(t2.second.second);
            use[t2.second.first].push_back(make_pair(t2.second.second,t2.first));
            use[t2.second.second].push_back(make_pair(t2.second.first,t2.first));
        }
    }
    F(1,0);
    while(Q--)
    {
        scanf("%lld %lld",&a,&b);
        printf("%lld\n",LCA(a,b));
    }
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector < pair < int , int > > Next[200005];
vector < pair < int , int > > use[200005];
priority_queue < pair < int , int > > all;
priority_queue < pair < int , pair < int , int > > > mst;
bool have[200005]={0};
int con[200005];
int Father[200005];
int who[25][200005];
int big[25][200005];
int deg[200005];
pair < int , pair < int , int > > t2;
pair < int , int > t;
int Find(int here)
{
    if(Father[here]=here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
int F(int here,int d)
{
    int i,j;
    have[here]=1;
    deg[here]=d;
    for(auto i:use[here])
    {
        if(!have[i.first])
        {
            who[0][i.first]=here;
            big[0][i.first]=i.second;
            for(j=1;(1<<j)<=d;j++)
            {
                who[j][i.first]=who[j-1][who[j-1][i.first]];
                big[j][i.first]=max(big[j-1][i.first],big[j-1][who[j-1][i.first]]);
            }
            F(i.first,d+1);
        }
    }

}
int LCA(int a,int b)
{
    int i;
    if(a==b) return 0;
    if(deg[a]>deg[b]) for(i=20;i>=0;i--) if(deg[a]-(1<<i)>=deg[b]) return max(F(who[i][a],b),big[i][a]);
    if(deg[a]<deg[b]) for(i=20;i>=0;i--) if(deg[b]-(1<<i)>=deg[a]) return max(F(a,who[i][b]),big[i][b]);
    if(who[0][a]==who[0][b]) return max(big[0][a],big[0][b]);
    for(i=20;i>=0;i--) if((1<<i)<=max(deg[a],deg[b])&&who[i][a]!=who[i][b]) return max(max(big[i][a],big[i][b]),F(who[i][a],who[i][b]));
}
int main()
{
	int N,M,K,Q,tt,i,a,b;
	scanf("%d %d %d %d",&N,&M,&K,&Q);
	for(i=0;i<M;i++)
	{
		scanf("%d %d %d",&a,&b,&tt);
		Next[a].push_back(make_pair(b,tt));
		Next[b].push_back(make_pair(a,tt));
	}
	for(i=1;i<=K;i++) all.push(make_pair(0,i));
	while(!all.empty())
	{
		t=all.top();
		all.pop();
		if(have[t.second]) continue;
		have[t.second]=1;
		con[t.second]=t.first;
		for(auto i:Next[t.second]) all.push(make_pair(t.first+i.second,i.first));
	}
	for(i=1;i<=N;i++)
    {
        have[i]=0;
        Father[i]=i;
        for(auto &j:Next[i])
        {
            j.second+=con[i];
            j.second+=con[j.first];
            mst.push(make_pair(j.second,make_pair(i,j.first)));
        }
    }
    while(!mst.empty())
    {
        t2=mst.top();
        mst.pop();
        if(Find(t2.second.first)!=Find(t2.second.second))
        {
            Father[Find(t2.second.first)]=Find(t2.second.second);
            use[t2.second.first].push_back(make_pair(t2.second.second,t2.first));
            use[t2.second.second].push_back(make_pair(t2.second.first,t2.first));
        }
    }
    F(1,0);
    while(Q--)
    {
        scanf("%d %d",&a,&b);
        printf("%d\n",LCA(a,b));
    }
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector < pair < int , int > > Next[200005];
vector < pair < int , int > > use[200005];
priority_queue < pair < int , int > , vector < pair < int , int > > , greater < pair < int , int > > > all;
priority_queue < pair < int , pair < int , int > > , vector < pair < int , pair < int , int > > > , greater < pair < int , pair < int , int > > > > mst;
bool have[200005]={0};
int con[200005];
int Father[200005];
int who[25][200005];
int big[25][200005];
int deg[200005];
pair < int , pair < int , int > > t2;
pair < int , int > t;
int Find(int here)
{
    if(Father[here]==here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
void F(int here,int d)
{
    int i,j;
    have[here]=1;
    deg[here]=d;
    for(auto i:use[here])
    {
        if(!have[i.first])
        {
            who[0][i.first]=here;
            big[0][i.first]=i.second;
            for(j=1;(1<<j)<=d;j++)
            {
                who[j][i.first]=who[j-1][who[j-1][i.first]];
                big[j][i.first]=max(big[j-1][i.first],big[j-1][who[j-1][i.first]]);
            }
            F(i.first,d+1);
        }
    }

}
int LCA(int a,int b)
{
    int i;
    if(a==b) return 0;
    if(deg[a]>deg[b]) for(i=20;i>=0;i--) if(deg[a]-(1<<i)>=deg[b]) return max(LCA(who[i][a],b),big[i][a]);
    if(deg[a]<deg[b]) for(i=20;i>=0;i--) if(deg[b]-(1<<i)>=deg[a]) return max(LCA(a,who[i][b]),big[i][b]);
    if(who[0][a]==who[0][b]) return max(big[0][a],big[0][b]);
    for(i=20;i>=0;i--) if((1<<i)<=max(deg[a],deg[b])&&who[i][a]!=who[i][b]) return max(max(big[i][a],big[i][b]),LCA(who[i][a],who[i][b]));
}
int main()
{
	int N,M,K,Q,tt,i,a,b;
	scanf("%d %d %d %d",&N,&M,&K,&Q);
	for(i=0;i<M;i++)
	{
		scanf("%d %d %d",&a,&b,&tt);
		Next[a].push_back(make_pair(b,tt));
		Next[b].push_back(make_pair(a,tt));
	}
	for(i=1;i<=K;i++) all.push(make_pair(0,i));
	while(!all.empty())
	{
		t=all.top();
		all.pop();
		//printf("bb %d %d\n",t.second,t.first);
		if(have[t.second]) continue;
		//printf("bb %d %d\n",t.second,t.first);
		have[t.second]=1;
		con[t.second]=t.first;
		for(auto i:Next[t.second]) all.push(make_pair(t.first+i.second,i.first));
	}
	for(i=1;i<=N;i++)
    {
        //printf("aa %d %d\n",i,con[i]);
        have[i]=0;
        Father[i]=i;
        for(auto &j:Next[i])
        {
            j.second+=con[i];
            j.second+=con[j.first];
            mst.push(make_pair(j.second,make_pair(i,j.first)));
        }
    }
    while(!mst.empty())
    {
        t2=mst.top();
        mst.pop();
        if(Find(t2.second.first)!=Find(t2.second.second))
        {
            //printf("cc %d %d %d %d %d\n",t2.second.first,t2.second.second,t2.first,Find(t2.second.first),Find(t2.second.second));
            Father[Find(t2.second.first)]=Find(t2.second.second);
            use[t2.second.first].push_back(make_pair(t2.second.second,t2.first));
            use[t2.second.second].push_back(make_pair(t2.second.first,t2.first));
        }
    }
    F(1,0);
    while(Q--)
    {
        scanf("%d %d",&a,&b);
        printf("%d\n",LCA(a,b));
    }
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector < pair < long long , long long > > Next[200005];
vector < pair < long long , long long > > use[200005];
priority_queue < pair < long long , long long > , vector < pair < long long , long long > > , greater < pair < long long , long long > > > all;
priority_queue < pair < long long , pair < long long , long long > > , vector < pair < long long , pair < long long , long long > > > , greater < pair < long long , pair < long long , long long > > > > mst;
bool have[200005]={0};
long long con[200005];
long long Father[200005];
long long who[25][200005];
long long big[25][200005];
long long deg[200005];
pair < long long , pair < long long , long long > > t2;
pair < long long , long long > t;
long long Find(long long here)
{
    if(Father[here]==here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
void F(long long here,long long d)
{
    //printf("%lld %lld\n",here,d);
    long long i,j;
    have[here]=1;
    deg[here]=d;
    for(j=1;(1<<j)<=d;j++)
    {

        who[j][here]=who[j-1][who[j-1][here]];
        big[j][here]=max(big[j-1][here],big[j-1][who[j-1][here]]);
        //printf("xx %lld %lld %lld\n",here,i.first,who[j][i.first]);
    }
    for(auto i:use[here])
    {
        if(!have[i.first])
        {
            who[0][i.first]=here;
            big[0][i.first]=i.second;
            F(i.first,d+1);
        }
    }

}
long long LCA(long long a,long long b)
{
    //printf("%lld %lld\n",a,b);
    long long i;
    if(a==b) return 0;
    if(deg[a]>deg[b]) for(i=20;i>=0;i--) if(deg[a]-(1<<i)>=deg[b]) return max(LCA(who[i][a],b),big[i][a]);
    if(deg[a]<deg[b]) for(i=20;i>=0;i--) if(deg[b]-(1<<i)>=deg[a]) return max(LCA(a,who[i][b]),big[i][b]);
    if(who[0][a]==who[0][b]) return max(big[0][a],big[0][b]);
    for(i=20;i>=0;i--) if((1<<i)<=max(deg[a],deg[b])&&who[i][a]!=who[i][b]) return max(max(big[i][a],big[i][b]),LCA(who[i][a],who[i][b]));
}
int main()
{
	long long N,M,K,Q,tt,i,a,b;
	scanf("%lld %lld %lld %lld",&N,&M,&K,&Q);
	for(i=0;i<M;i++)
	{
		scanf("%lld %lld %lld",&a,&b,&tt);
		Next[a].push_back(make_pair(b,tt));
		Next[b].push_back(make_pair(a,tt));
	}
	for(i=1;i<=K;i++) all.push(make_pair(0,i));
	while(!all.empty())
	{
		t=all.top();
		all.pop();
		//printf("bb %lld %lld\n",t.second,t.first);
		if(have[t.second]) continue;
		//printf("bb %lld %lld\n",t.second,t.first);
		have[t.second]=1;
		con[t.second]=t.first;
		for(auto i:Next[t.second]) all.push(make_pair(t.first+i.second,i.first));
	}
	for(i=1;i<=N;i++)
    {
        //printf("aa %lld %lld\n",i,con[i]);
        have[i]=0;
        Father[i]=i;
        for(auto &j:Next[i])
        {
            j.second+=con[i];
            j.second+=con[j.first];
            mst.push(make_pair(j.second,make_pair(i,j.first)));
        }
    }
    while(!mst.empty())
    {
        t2=mst.top();
        mst.pop();
        if(Find(t2.second.first)!=Find(t2.second.second))
        {
            //printf("cc %lld %lld %lld %lld %lld\n",t2.second.first,t2.second.second,t2.first,Find(t2.second.first),Find(t2.second.second));
            Father[Find(t2.second.first)]=Find(t2.second.second);
            use[t2.second.first].push_back(make_pair(t2.second.second,t2.first));
            use[t2.second.second].push_back(make_pair(t2.second.first,t2.first));
        }
    }
    F(1,0);
    while(Q--)
    {
        scanf("%lld %lld",&a,&b);
        printf("%lld\n",LCA(a,b));
    }
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>
#include <queue>
using namespace std;
vector < pair < int , int > > Next[200005];
vector < pair < int , int > > use[200005];
priority_queue < pair < int , int > > all;
priority_queue < pair < int , pair < int , int > > > mst;
bool have[200005]={0};
int con[200005];
int Father[200005];
int who[25][200005];
int big[25][200005];
int deg[200005];
pair < int , pair < int , int > > t2;
pair < int , int > t;
int Find(int here)
{
    if(Father[here]=here) return here;
    Father[here]=Find(Father[here]);
    return Father[here];
}
void F(int here,int d)
{
    int i,j;
    have[here]=1;
    deg[here]=d;
    for(auto i:use[here])
    {
        if(!have[i.first])
        {
            who[0][i.first]=here;
            big[0][i.first]=i.second;
            for(j=1;(1<<j)<=d;j++)
            {
                who[j][i.first]=who[j-1][who[j-1][i.first]];
                big[j][i.first]=max(big[j-1][i.first],big[j-1][who[j-1][i.first]]);
            }
            F(i.first,d+1);
        }
    }

}
int LCA(int a,int b)
{
    int i;
    if(a==b) return 0;
    if(deg[a]>deg[b]) for(i=20;i>=0;i--) if(deg[a]-(1<<i)>=deg[b]) return max(LCA(who[i][a],b),big[i][a]);
    if(deg[a]<deg[b]) for(i=20;i>=0;i--) if(deg[b]-(1<<i)>=deg[a]) return max(LCA(a,who[i][b]),big[i][b]);
    if(who[0][a]==who[0][b]) return max(big[0][a],big[0][b]);
    for(i=20;i>=0;i--) if((1<<i)<=max(deg[a],deg[b])&&who[i][a]!=who[i][b]) return max(max(big[i][a],big[i][b]),LCA(who[i][a],who[i][b]));
}
int main()
{
	int N,M,K,Q,tt,i,a,b;
	scanf("%d %d %d %d",&N,&M,&K,&Q);
	for(i=0;i<M;i++)
	{
		scanf("%d %d %d",&a,&b,&tt);
		Next[a].push_back(make_pair(b,tt));
		Next[b].push_back(make_pair(a,tt));
	}
	for(i=1;i<=K;i++) all.push(make_pair(0,i));
	while(!all.empty())
	{
		t=all.top();
		all.pop();
		if(have[t.second]) continue;
		have[t.second]=1;
		con[t.second]=t.first;
		for(auto i:Next[t.second]) all.push(make_pair(t.first+i.second,i.first));
	}
	for(i=1;i<=N;i++)
    {
        have[i]=0;
        Father[i]=i;
        for(auto &j:Next[i])
        {
            j.second+=con[i];
            j.second+=con[j.first];
            mst.push(make_pair(j.second,make_pair(i,j.first)));
        }
    }
    while(!mst.empty())
    {
        t2=mst.top();
        mst.pop();
        if(Find(t2.second.first)!=Find(t2.second.second))
        {
            Father[Find(t2.second.first)]=Find(t2.second.second);
            use[t2.second.first].push_back(make_pair(t2.second.second,t2.first));
            use[t2.second.second].push_back(make_pair(t2.second.first,t2.first));
        }
    }
    F(1,0);
    while(Q--)
    {
        scanf("%d %d",&a,&b);
        printf("%d\n",LCA(a,b));
    }
	return 0;
}


 #include<bits/stcd++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min=INT_MAX,min1=INT_MAX,max=INT_MIN,max1=INT_MIN;
int a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min=min(min,i+1);
            max=max(max,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max-min)/2<<" "<<(max1-min1)/2<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min2=INT_MAX,min1=INT_MAX,max2=INT_MIN,max1=INT_MIN;
char a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min2=min(min2,i+1);
            max2=max(max2,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max2+min2)/2<<" "<<(max1+min1)/2<<endl;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min=INT_MAX,min1=INT_MAX,max=INT_MIN,max1=INT_MIN;
int a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min=min(min,i+1);
            max=max(max,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max-min)/2<<" "<<(max1-min1)/2<<endl;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min2=INT_MAX,min1=INT_MAX,max2=INT_MIN,max1=INT_MIN;
int a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min2=min(min2,i+1);
            max2=max(max2,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max2+min2)/2<<" "<<(max1+min1)/2<<endl;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min=INT_MAX,min1=INT_MAX,max=INT_MIN,max1=INT_MIN;
char a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min=min(min,i+1);
            max=max(max,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max+min)/2<<" "<<(max1+min1)/2<<endl;
}


#include<bits/stc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
int min=INT_MAX,min1=INT_MAX,max=INT_MIN,max1=INT_MIN;
int a[n][m];
for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        cin>>a[i][j];
        if(a[i][j]=='B')
        {
            min=min(min,i+1);
            max=max(max,i+1);
            min1=min(min1,j+1);
            max1=max(max1,j+1);
        }
    }
}
cout<<(max-min)/2<<" "<<(max1-min1)/2<<endl;
}


#include <bits/stdc++.h>
#include<algorithm>
#define ll long long
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define MAXN 1000000007
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
using namespace std;

int main(void) {
     ios::sync_with_stdio(0);
     int n, m , ans1 = -1, ans2 = -1, temp1 = 0 , flag = 0, length = 0 ;
     cin >> n >> m  ;
     for(int i = 0 ; i < n ; i++)
     {
          char s[m] ;
          for(int j = 0 ; j<m ; ++j)
               {
                    cin >> s[j] ;
                    if(s[j] == 'B' && flag == 0)
                    {
                         flag = 1 ;
                         temp1 = j ;
                       //  cout << "ll\n";
                      // cout << flag << " " ;
                    }
                    //cout << j << endl ;
                    if((flag == 1 && s[j] == 'W' )|| (j == m-1 && flag == 1))
                    {
                         //cout << flag << endl ;
                         length = j - temp1 + 1 ;
                         ans1 = i + (1+length)/2 ;
                         ans2 = (j+ temp1)/2 + 1;
                         //cout << length << endl ;
                         flag  = 2 ;
                    }
               }
     }
     cout << ans1 << " " << ans2;
}


#include <bits/stdc++.h>
#include<algorithm>
#define ll long long
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define MAXN 1000000007
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
using namespace std;

int main(void) {
     ios::sync_with_stdio(0);
     int n, m , ans1 = 1, ans2 = 1, temp1 = 0 , flag = 0, length = 0 ;
     cin >> n >> m  ;
     for(int i = 0 ; i < n ; i++)
     {
          char s[m] ;
          for(int j = 0 ; j<m ; ++j)
               {
                    cin >> s[j] ;
                    if(s[j] == 'B' && flag == 0)
                    {
                         flag = 1 ;
                         temp1 = j ;
                       //  cout << "ll\n";
                    }
                    if((flag == 1 && s[j] == 'W' )|| (j == n-1 && flag == 1))
                    {
                         length = j - temp1 + 1 ;
                         ans1 = i + (1+length)/2 ;
                         ans2 = (j+ temp1)/2 + 1;
                         flag  = 2 ;
                    }
               }
     }
     cout << ans1 << " " << ans2;
}


#include <bits/stdc++.h>
#include<algorithm>
#define ll long long
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define MAXN 1000000007
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
using namespace std;

int main(void) {
     ios::sync_with_stdio(0);
     int n, m , ans1 = 1, ans2 = 1, temp1 = 0 , flag = 0, length = 0 ;
     cin >> n >> m  ;
     for(int i = 0 ; i < n ; i++)
     {
          char s[m] ;
          for(int j = 0 ; j<m ; ++j)
               {
                    cin >> s[j] ;
                    if(s[j] == 'B' && flag == 0)
                    {
                         flag = 1 ;
                         temp1 = j ;
                       //  cout << "ll\n";
                    }
                    if((flag == 1 && s[j] == 'W' )|| (j == n-1 && flag == 1))
                    {
                         length = j - temp1 + 1 ;
                         ans1 = i + length/2 + 1;
                         ans2 = (j+ temp1)/2 + 1;
                         flag  = 2 ;
                    }
               }
     }
     cout << ans1 << " " << ans2;
}


#include <bits/stdc++.h>
#include<algorithm>
#define ll long long
#define pb push_back
#define popb pop_back
#define ull unsigned long long
#define beg begin
#define MAXN 1000000007
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
using namespace std;

int main(void) {
     ios::sync_with_stdio(0);
     int n, m , ans1 = -1, ans2 = -1, temp1 = 0 , flag = 0, length = 0 ;
     cin >> n >> m  ;
     for(int i = 0 ; i < n ; i++)
     {
          char s[m] ;
          for(int j = 0 ; j<m ; ++j)
               {
                    cin >> s[j] ;
                    if(s[j] == 'B' && flag == 0)
                    {
                         flag = 1 ;
                         temp1 = j ;
                       //  cout << "ll\n";
                      // cout << flag << " " ;
                    }
                    //cout << j << endl ;
                    if((flag == 1 && s[j] == 'W' )|| (j == m-1 && flag == 1))
                    {
                         //cout << flag << endl ;
                         length = j - temp1 + 1 ;
                         ans1 = i + (1+length)/2 ;
                         ans2 = (j+ temp1)/2 + 1;
                         cout << length << endl ;
                         flag  = 2 ;
                    }
               }
     }
     cout << ans1 << " " << ans2;
}


#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was
Only through dedication will I destroy all preconception
No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past
Only through dedication will I destroy all preconception
Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration
Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be
Join me,
Walk with me

*/
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;

    bool flag = false;

    char a[n][m];

    loop(i, n)
        loop(j, m)
            cin >> a[i][j];

    int row = 0, col = 0;

    loop(i, n){
        ans = cnt;
        cnt = 0;
        loop(j, m){
            if(a[i][j] == 'B' && !flag){
                flag = true;
                row = i;
                col = j;
            }
            if(a[i][j] == 'B'){
                cnt++;
            }
        }
    }
    row++;
    col++;
  // cout << row << " " << col << " " << len << "\n";
    row += ans/2;
    col +=  ans/2;

    cout << row << " " << col;

}
int main(){
    FIO
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was
Only through dedication will I destroy all preconception
No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past
Only through dedication will I destroy all preconception
Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration
Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be
Join me,
Walk with me

*/
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;

    bool flag = false;

    char a[n][m];

    loop(i, n)
        loop(j, m)
            cin >> a[i][j];

    int row, col, len;

    loop(i, n){
        loop(j, m){
            if(a[i][j] == 'B' && !flag){
                flag = true;
                row = i;
                col = j;
            }
            else if(a[i][j] == 'W' && flag){
                len = i - row-1;
                break;
            }
        }
    }
    row++;
    col++;
   // cout << row << " " << col << " " << len << "\n";
    row += len/2;
    col +=  len/2;

    cout << row << " " << col;

}
int main(){
    FIO
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was
Only through dedication will I destroy all preconception
No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past
Only through dedication will I destroy all preconception
Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration
Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be
Join me,
Walk with me

*/
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;

    bool flag = false;

    char a[n][m];

    loop(i, n)
        loop(j, m)
            cin >> a[i][j];

    int row = 0, col = 0;

    loop(i, n){
        //cout << ans << " " << cnt << "\n";
        ans = max(cnt, ans);
        cnt = 0;
        loop(j, m){
            if(a[i][j] == 'B' && !flag){
                flag = true;
                row = i;
                col = j;
            }
            if(a[i][j] == 'B'){
                cnt++;
            }
        }
    }
    row++;
    col++;
   //cout << row << " " << col << " " << ans << "\n";
    row += ans/2;
    col +=  ans/2;

    cout << row << " " << col;

}
int main(){
    FIO
    solve();
    return 0;
}


#include<bits/stdc++.h>
#define loop(i, n) for(int i = 0; i < n; i++)
#define pb          push_back
#define ll          long long int
#define vi          vector<int>
#define pi          pair<int, int>
#define W(t)        int t; cin >> t; while(t--)
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ff          first
#define ss          second
using namespace std;
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was
Only through dedication will I destroy all preconception
No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past
Only through dedication will I destroy all preconception
Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration
Join me,
Walk with me
Shatter the bonds that tie us
To what we strive to never be
Join me,
Walk with me

*/
void solve(){
    int i, j, k, m, n, ans = 0, cnt = 0;

    cin >> n >> m;

    bool flag = false;

    char a[n][m];

    loop(i, n)
        loop(j, m)
            cin >> a[i][j];

    int row, col, len = m;

    loop(i, n){
        loop(j, m){
            if(a[i][j] == 'B' && !flag){
                flag = true;
                row = i;
                col = j;
            }
            else if(a[i][j] == 'W' && flag){
                len = i - row-1;
                break;
            }
        }
    }
    row++;
    col++;
   // cout << row << " " << col << " " << len << "\n";
    row += len/2;
    col +=  len/2;

    cout << row << " " << col;

}
int main(){
    FIO
    solve();
    return 0;
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX=2*1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c=-1;
	a = -1;
	b = -1;
	char x;
	for (int i = 0; i < n; i++) {

		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
			}
			else {
				if (a != -1 && b==-1) b = j-1;
			}
		}
		if (a != -1 && b == -1) b =n-1;
		if (c != -1 && a != -1 && b != -1)
		{
			cout << c + (b - a) / 2 + 1 << ' ' << ((a + b) / 2) + 1 << endl;
			//cout << a << ' ' << b << ' ' << c;
			return(0);
		}
	}
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX = 2 * 1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c = -1;
	a = -1;
	b = -1;
	char x;
	for (int i = 0; i < n; i++) {

		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
				b = j;
			}
		}
		if (a != -1 && b == -1) b = n - 1;
		if (c != -1 && a != -1 && b != -1)
		{
			cout << c + (b - a) / 2 + 1 << ' ' << ((a + b) / 2) + 1 << endl;
			//cout << a << ' ' << b << ' ' << c;
			return(0);
		}
	}
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX=2*1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c=-1;
	a = -1;
	b = -1;
	char x;
	for (int i = 0; i < n; i++) {
		if (c != -1)
		{
			cout  << c + (b - a) / 2+1 <<' '<< ((a + b) / 2) + 1  <<endl;
			//cout << a << ' ' << b<<' '<<c;
			return(0);
		}
		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
			}
			else {
				if (a != -1) b = j-1;
			}
		}
	}
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX=2*1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c=-1;
	a = -1;
	b = -1;
	char x;
	for (int i = 0; i < n; i++) {
		if (c != -1)
		{
			cout  << c + (b - a) / 2+1 <<' '<< ((a + b) / 2) + 1  <<endl;
			//cout << a << ' ' << b<<' '<<c;
			return(0);
		}
		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
			}
			else {
				if (a != -1 && b==-1) b = j-1;
			}
		}
	}
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX = 2 * 1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c = -1;
	a = -1;
	b = -1;
	char x;
	for (int i = 0; i < n; i++) {

		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
			}
			else {
				if (a != -1 && b == -1) b = j - 1;
			}
		}
		if (a != -1 && b == -1) b = n - 2;
		if (c != -1 && a != -1 && b != -1)
		{
			cout << c + (b - a) / 2 + 1 << ' ' << ((a + b) / 2) + 1 << endl;
			//cout << a << ' ' << b << ' ' << c;
			return(0);
		}
	}
}


#include <vector>
#include <algorithm>
#include <fstream>
#include<string>
#include <iostream>
#include <map>
# include <set>
#include<cmath>
#include <numeric>
using namespace std;

const long long int kek = 1e14;
const int MX=2*1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	int a, b;
	int c=-1;
	char x;
	for (int i = 0; i < n; i++) {
		if (c != -1)
		{
			cout  << c + (b - a) / 2+1 <<' '<< ((a + b) / 2) + 1  <<endl;
			//cout << a << ' ' << b<<' '<<c;
			return(0);
		}
		a = -1;
		b = -1;
		for (int j = 0; j < m; j++) {
			cin >> x;
			if (x == 'B') {
				if (a == -1) a = j;
				if (c == -1) c = i;
			}
			else {
				if (a != -1) b = j-1;
			}
		}
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char a[n+1][m+1];
    FOR(i,n)
    {
        FOR(j,m)
        {
            cin>>a[i][j];
        }
    }
    int sr=0,er=0,sc=0,ec=0,pre=0;
    FOR(i,n)
    {
        FOR(j,m)
        {
            if(a[i][j]=='B' and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(a[i][j]=='B' and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(int i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char c, cnst='B';
    int sr=0,er=0,sc=0,ec=0,pre=0,i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>c;
            if(c==cnst and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(c==cnst and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<stdio.h>
#include<string.h>
//using namespace std;
#define ll                   long long int
//#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(int i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
//#define pb                   push_back
//#define mp                   make_pair
//#define vi                   vector<int>

/*void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}*/

int main()
{
    //fastio();
    int n,m;
    sci(n);
    sci(m);
    char c, cnst='B';
    int sr=0,er=0,sc=0,ec=0,pre=0,i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            scanf(" %c",&c);
            if(c==cnst && pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(c==cnst && pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    printf("%d %d",(sr+((er-sr)/2)),(sc+((ec-sc)/2)));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(int i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char c, cnst='B';

    int sr=0,er=0,sc=0,ec=0,pre=0,i,j;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=m;j++)
        {
            cin>>c;
            if(c==cnst and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(c==cnst and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char a[n+1][m+1];
    FOR(i,n)
    {
        FOR(j,m)
        {
            cin>>a[i][j];
        }
    }
    int sr=0,er=0,sc=0,ec=0,pre=0;
    FOR(i,n)
    {
        FOR(j,m)
        {
            if(a[i][j]=="B" and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(a[i][j]=="B" and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(int i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char a[n+1][m+1];
    LOOP(i,n)
    {
        LOOP(j,m)
        {
            cin>>a[i][j];
        }
    }
    int sr=0,er=0,sc=0,ec=0,pre=0;
    LOOP(i,n)
    {
        LOOP(j,m)
        {
            if(a[i][j]=='B' and pre==0)
            {
                sr=i+1;
                sc=j+1;
                pre=1;
            }
            if(a[i][j]=='B' and pre==1)
            {
                er=i+1;
                ec=j+1;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(int i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char c;
    int sr=0,er=0,sc=0,ec=0,pre=0;
    FOR(i,n)
    {
        FOR(j,m)
        {
            cin>>c;
            if(c=='B' and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(c=='B' and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll                   long long int
#define endl                 "\n"
#define PI                   acos(-1)
#define sci(n)               scanf("%d",&n)
#define scl(n)               scanf("%lld",&n)
#define scd(n)               scanf("%lf",&n)
#define FOR(i,n)             for(int i=1;i<=n;i++)
#define LOOP(i,n)            for(ll i=0;i<n;i++)
#define loop(a,b)            for(ll i=a;i<=b;i++)
#define pb                   push_back
#define mp                   make_pair
#define vi                   vector<int>

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

int main()
{
    fastio();
    int n,m;
    sci(n);
    sci(m);
    char a[n+100][m+100];
    FOR(i,n)
    {
        FOR(j,m)
        {
            cin>>a[i][j];
        }
    }
    int sr=0,er=0,sc=0,ec=0,pre=0;
    FOR(i,n)
    {
        FOR(j,m)
        {
            if(a[i][j]=='B' and pre==0)
            {
                sr=i;
                sc=j;
                pre=1;
            }
            if(a[i][j]=='B' and pre==1)
            {
                er=i;
                ec=j;
            }
        }
    }
    cout<<(sr+((er-sr)/2))<<" "<<(sc+((ec-sc)/2))<<endl;
    return 0;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll n, m, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> m;

    for(int i = 0; i < n*m; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        last = temp;
    }

    cout << (first/m + last/m)/2+1 << " " <<(first%n + last%n)/2 +1 ;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll r, c, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> r >> c;

    for(int i = 0; i < r*c; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        if(temp == 'B')last = i;
    }
  // cout << "last : " << last << "// first : " << first <<endl;
    cout << (first/c+last/c)/2 +1 << " " << (first%c + last%c)/2 + 1;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll r, c, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> r >> c;

    for(int i = 0; i < r*c; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        if(temp == 'B')last = i;
    }
    cout << "last : " << last << "// first : " << first <<endl;
    cout << (first/c+last/c)/2 +1 << " " << (first%c + last%c)/2 + 1;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll r, c, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> r >> c;

    for(int i = 0; i < r*c; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        if(temp == 'B')last = temp;
    }

    cout << (first/c+last/c)/2 +1 << " " << (first%c + last%c)/2 + 1;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll r, c, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> r >> c;

    for(int i = 0; i < r*c; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        last = temp;
    }

    cout << (first+last)/c +1 << " " << (first + last)%c + 1;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll r, c, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> r >> c;

    for(int i = 0; i < r*c; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        last = temp;
    }

    cout << (first/c+last/c)/2 +1 << " " << (first%c + last%c)/2 + 1;
}


//https://codeforces.com/problemset/problem/1028/A
//code by Hank Jin               blog HankJin.github.io

#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;

ll n, m, first = -1, last = -1;
char temp;

int main(){

    std::ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n >> m;

    for(int i = 0; i < n*m; i++){
        cin >> temp;
        if(temp == 'B' && first == -1) first = i;
        last = temp;
    }

    cout << (first%n + last%n)/2 +1 << " " << (first/m + last/m)/2+1;
}


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

string a[120];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i =0; i<n; i++){
		cin >> a[i];
	}
	long long int cnt = 0;
	long long int I = 0,J = 0;
	bool flag = false;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i][j] == 'B'){
				cnt ++;
				I = i;
				J = j;
				flag = true;
			}
		}
		if(flag)
			break;
	}
	cout << I + cnt/2 + 1 << " " <<  J + 1 - (cnt/2) ;
	return 0;
}


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

string a[120];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i =0; i<n; i++){
		cin >> a[i];
	}
	int cnt = 0;
	int I,J;
	bool flag = false;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i][j] == 'B'){
				cnt ++;
				I = i;
				J = j;
				flag = true;
			}
		}
		if(flag)
			break;
	}
	cout << I + cnt/2 + 1 << " " <<  J - cnt/2 + 1;
	return 0;
}


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

string a[120];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i =0; i<n; i++){
		cin >> a[i];
	}
	int cnt = 0;
	int I = 0,J = 0;
	bool flag = false;
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(a[i][j] == 'B'){
				cnt ++;
				I = i;
				J = j;
				flag = true;
//				cout << a[i] << endl;
			}
		}
//		cout << a[i] << endl;
		if(flag)
			break;
	}
	cout << I + cnt/2 + 1 << " " <<  J - cnt/2 + 1 ;
	return 0;
}


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

string a[120];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i =0; i<n; i++){
		cin >> a[i];
	}
	int cnt = 0;
	int I,J;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i][j] == 'B'){
				cnt ++;
				I = i;
				J = j;
				break;
			}
		}
	}
	cout << I - cnt/2 + 1 << " " <<  J + cnt/2 + 1;
	return 0;
}


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

string a[120];
int main(){
	int n,m;
	cin >> n >> m;
	for(int i =0; i<n; i++){
		cin >> a[i];
	}
	long long int cnt = 0;
	int I = 0,J = 0;
	bool flag = false;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i][j] == 'B'){
				cnt ++;
				I = i;
				J = j;
				flag = true;
			}
		}
		if(flag)
			break;
	}
	cout << I + cnt/2 + 1 << " " <<  J - cnt/2 + 1;
	return 0;
}


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0, c;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B') { a+=i; b+=j; c++; }
		}
	}
	cout << a / c << " " << b / c << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	string ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i];
	}
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(ar[i][j]=='B')
			{
				goto s;
			}
		}
	}
       s:
	int k=j;
	int c=0;
	while(k<m && ar[i][k]=='B')
	{
		c++;
		k++;
	}
	int d=c/2;
	cout<<i+d+1<<" "<<j+d+1<<endl;
	return 0;
    }


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0, c;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B') { a+=i; b+=j; c++; }
		}
	}
	cout << a / c + 1 << " " << b / c + 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0, c = 0;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B') { a+=i; b+=j; c++; }
		}
	}
	cout << a / c + 1 << " " << b / c + 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; i < j; i++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B') { a+=i; b+=j; }
		}
	}
	cout << a / 2 + 1 << " " << b / 2 + 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; i < j; i++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B')
			{
			    a++;
				b++;
			}
		}
	}
	cout << a / 2 + 1 << " " << b / 2 + 1 << endl;
	return 0;
}


#include <iostream>

using namespace std;

int main ()
{
	int n, m, a = 0, b = 0;
	cin >> n >> m;
	char s [n][m];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> s [i][j];
			if (s [i][j] == 'B') { a++; b++; }
		}
	}
	cout << a / 2 + 1  << " " << b / 2 + 1 << endl;
	return 0;
}


//
// In the Name of God, the Beneficent, the Merciful
//

#include <bits/stdc++.h>

#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define get() _getchar_nolock()
#define put(c) _putchar_nolock(c)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

int main()
{
    IOS;

    int n, m, fr, lr, fc, lc;
    bool f = true, ff = true;
    string a;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a.find_last_of('B') != -1)
        {
            if (ff)
            {
                fr = a.find_last_of('B');
                lr = a.find_first_of('B');
                ff = false;
            }
            if (f)
                fc = i, f = false;
            lc = i;
        }
    }
    cout << (fc + lc) / 2 + 1 << ' ' << (fr + lr) / 2 + 1;
}


//
// In the Name of God, the Beneficent, the Merciful
//

#include <bits/stdc++.h>

#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define get() _getchar_nolock()
#define put(c) _putchar_nolock(c)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

int main()
{
    IOS;

    int n, m, r = 0, fB, c, t;
    bool f = false;
    cin >> n >> m;
    string a;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        c = a.find_last_of('B') + a.find_first_of('B');
        if (c != -2)
        {

            if (!f)
            {
                t = c / 2 + 1;
                fB = i;
                f = true;
            }
            else
                r++;
        }
    }
    if (r != 0)
        fB = (r + fB) / 2 + 1;
    cout << fB << ' ' << t;
}


//
// In the Name of God, the Beneficent, the Merciful
//

#include <bits/stdc++.h>

#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define get() _getchar_nolock()
#define put(c) _putchar_nolock(c)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

int main()
{
    IOS;

    int n, m, fr, lr, fc, lc;
    bool f = true;
    string a;
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        if (a.find_last_of('B') != -1)
        {
            fr = a.find_last_of('B');
            lr = a.find_first_of('B');
            if (f)
                fc = i, f = false;
            lc = i;
        }
    }
    cout << (fc + lc) / 2 + 1 << ' ' << (fr + lr) / 2 + 1;
}


//
// In the Name of God, the Beneficent, the Merciful
//

#include <bits/stdc++.h>

#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define get() _getchar_nolock()
#define put(c) _putchar_nolock(c)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

int main()
{
    IOS;

    int n, m, r = 0, fB, c, t;
    bool f = false;
    cin >> n >> m;
    string a;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        c = a.find_last_of('B') + a.find_first_of('B');
        if (c != -2)
        {

            if (!f)
            {
                t = c / 2+1;
                fB = i;
                f = true;
            }
            else
                r++;
        }
    }
    cout << (r + fB) / 2+1 << ' ' << t;
}


//
// In the Name of God, the Beneficent, the Merciful
//

#include <bits/stdc++.h>

#define endl '\n'
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define get() _getchar_nolock()
#define put(c) _putchar_nolock(c)

using namespace std;

typedef vector<int> vi;
typedef long long ll;
typedef long double ld;

int main()
{
    IOS;

    int n, m, r = 0, fB, c, t;
    bool f = false;
    string a;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> a;
        c = a.find_last_of('B') + a.find_first_of('B');
        if (c >= 0)
        {
            if (!f)
            {
                t = c / 2 + 1;
                fB = i;
                f = true;
            }
            r++;
        }
    }
    fB = (r + fB) / 2 + 1;
    cout << fB << ' ' << t;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<vector<char>> v;

pair<ll, ll> search(ll n, ll m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == 'B') {
                return {i, j};
            }
        }
    }
}
int main() {
    freopen("input.txt", "r", stdin);
    ll n, m;
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++)
        v[i].resize(m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> v[i][j];
    ll r = 0, c = 0;
    pair<ll, ll> tmp;
    tmp = search(n, m);
    r = tmp.first;
    c = tmp.second;
    ll k = 1;
    while (v[r + k][c] == 'B') {
        k++;
    }
    r += (k / 2);
    c += (k / 2);
    cout << r + 1 << " " << c + 1;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<vector<char>> v;

pair<ll, ll> search(ll n, ll m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == 'B') {
                return {i, j};
            }
        }
    }
}
int main() {
    //freopen("input.txt", "r", stdin);
    ll n, m;
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++)
        v[i].resize(m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> v[i][j];
    ll r = 0, c = 0;
    pair<ll, ll> tmp;
    tmp = search(n, m);
    r = tmp.first;
    c = tmp.second;
    ll k = 1;
    while (v[r + k][c] == 'B') {
        k++;
    }
    r += (k / 2);
    c += (k / 2);
    cout << r + 1 << " " << c + 1;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<vector<char>> v;

pair<ll, ll> search(ll n, ll m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == 'B') {
                return {i, j};
            }
        }
    }
}
int main() {
    freopen("input.txt", "r", stdin);
    ll n, m;
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++)
        v[i].resize(m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> v[i][j];
    ll r = 0, c = 0;
    pair<ll, ll> tmp;
    tmp = search(n, m);
    r = tmp.first;
    c = tmp.second;
    ll k = 1;
    while (r + k < n &&v[r + k][c] == 'B') {
        k++;
    }
    r += (k / 2);
    c += (k / 2);
    cout << r + 1 << " " << c + 1;
    return 0;
}


#include <bits/stdc++.h>

#define ll long long

using namespace std;

vector<vector<char>> v;

pair<ll, ll> search(ll n, ll m) {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == 'B') {
                return {i, j};
            }
        }
    }
}
int main() {
    //freopen("input.txt", "r", stdin);
    ll n, m;
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++)
        v[i].resize(m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> v[i][j];
    ll r = 0, c = 0;
    pair<ll, ll> tmp;
    tmp = search(n, m);
    r = tmp.first;
    c = tmp.second;
    ll k = 1;
    while (r + k < n &&v[r + k][c] == 'B') {
        k++;
    }
    r += (k / 2);
    c += (k / 2);
    cout << r + 1 << " " << c + 1;
    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;
const int maxn = 1050;
char mp[maxn][maxn];
int dp[maxn][maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%s",mp[i]+1);
    int cnt = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(mp[i][j] == 'B')
            {
                cnt++;
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
        }
    int bei = 0, bej = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(dp[i][j] == 1)
                bei = i,bej = j;
             if(dp[i][j] == cnt)
            {
                printf("%d %d\n",(i+bei) / 2, (j + bej) / 2);
                return 0;
            }

        }

    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;
const int maxn = 1050;
char mp[maxn][maxn];
int dp[maxn][maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
   	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>mp[i][j];
    int cnt = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(mp[i][j] == 'B')
            {
                cnt++;
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];

        }
    int bei = 0, bej = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(mp[i][j] == 'W')continue;
            if(dp[i][j] == 1)
                bei = i,bej = j;
            if(dp[i][j] == cnt)
            {
                printf("%d %d\n",(i+bei) / 2, (j + bej) / 2);
                return 0;
            }

        }

    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;
const int maxn = 1050;
char mp[maxn][maxn];

int dir[8][2] = {0,1,0,-1,1,0,-1,0,1,1,1,-1,-1,1,-1,-1};
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1; i<=n; i++)
        scanf("%s",mp[i]+1);

    for(int i=1; i<=n; i++)
        for(int j=1; j<=n; j++)
        {
            if(mp[i][j] == 'B')
            {
                int time = 0;
                while(1)
                {
                   time++;
                    int cnt = 0;
                    for(int t=0; t<8; t++)
                    {
                        int nx = i + time * dir[t][0];
                        int ny = j + time * dir[t][1];
                        if(nx >=1 && nx <= n && ny >= 1 &&ny<=m)
                        {
                            if(mp[nx][ny] == 'B')
                                cnt++;
                        }
                    }
                    if(cnt == 0)
                    {
                        printf("%d %d\n",i,j);
                        return 0;
                    }
                    else if(cnt < 8)
                        break;
                    else
                        continue;
                }
            }
        }

    return 0;
}


#include <cstdio>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

typedef long long ll;
const int maxn = 1050;
char mp[maxn][maxn];
int dp[maxn][maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
   	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>mp[i][j];
    int cnt = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            if(mp[i][j] == 'B')
            {
                cnt++;
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1] + 1;
            }
            else
                dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];

        }
    int bei = 0, bej = 0;
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            if(mp[i][j] == 'W')continue;
            if(dp[i][j] == 1)
                bei = i,bej = j;
            if(dp[i][j] == cnt)
            {
                printf("%d %d\n",(i+bei) / 2, (j + bej) / 2);
                return 0;
            }

        }

    return 0;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

#define loop(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef string str;

int main ()
{
	int n,m;
	cin >> n >> m;

	char table[1000][1000];
	loop(i , n)
		loop(j , m)
			cin >> table[i][j];

	//~ int sum = 0;
	vector<int> arr;
	loop(i, n)
		loop(j , m)
			if (table[i][j] == 'B')
			{
				arr.push_back(i+1);
				arr.push_back(j+1);
				//~ sum ++;
			}

	//~ cout << arr.size()  << "\n";
	//~ for (int i=0;i<arr.size();i+=2)
		//~ cout << arr[i] << " " << arr[i+1] << "|";
	//~ cout << "\n";
	cout << arr[arr.size() / 2 -1] << " " << arr[arr.size() / 2] ;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

#define loop(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef string str;

int main ()
{
	int n,m;
	cin >> n >> m;

	char table[100][100];
	loop(i , n)
		loop(j , m)
			cin >> table[i][j];

	int sum = 0;
	bool first = false;
	pair<int , int> p;
	loop(i, n)
		loop(j , m)
			if (table[i][j] == 'B')
			{
				if (first == false)
				{
					p.first = i+1;
					p.second = j+1;
					first = true;
				}
				sum ++;
			}

	int s = sqrt(sum);
	if (s != 1)
	cout << p.first + s - 2 << " " << p.second + s - 2;
	else
	cout << p.first <<  " "<< p.second;
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

#define loop(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef string str;

int main ()
{
	int n,m;
	cin >> n >> m;

	char table[1000][1000];
	loop(i , n)
		loop(j , m)
			cin >> table[i][j];

	loop(i, n)
		loop(j , m)
			if (table[i][j] == 'B')
			{
				cout << i + 2 << " " << j + 2;
				return 0;
			}
}


#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

#define loop(i,n) for(int i=0;i<n;++i)
typedef long long ll;
typedef string str;

int main ()
{
	int n,m;
	cin >> n >> m;

	char table[100][100];
	loop(i , n)
		loop(j , m)
			cin >> table[i][j];

	//~ int sum = 0;
	vector<int> arr;
	loop(i, n)
		loop(j , m)
			if (table[i][j] == 'B')
			{
				arr.push_back(i+1);
				arr.push_back(j+1);
				//~ sum ++;
			}

	//~ cout << arr.size()  << "\n";
	//~ for (int i=0;i<arr.size();i+=2)
		//~ cout << arr[i] << " " << arr[i+1] << "|";
	//~ cout << "\n";
	cout << arr[arr.size() / 2 -1] << " " << arr[arr.size() / 2] ;
}


#include<bits/stdc++.h>

int X,Y,n,m,cnt;char s[200];
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++){
		scanf("%s",s+1);
		for (int j=1;j<=m;j++)
			if (s[j]=='B') cnt++,X+=i,Y+=j;
	}
	X/=cnt;Y/=cnt;
	printf("%d %d\n",X,Y);
}


#include<cstdio>

int n, m, sx, sy, cc;
char s[120][120];

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%s", s[i] + 1);
        for(int j=1; j<=m; j++){
            if(s[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


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

int n, m, sx, sy, cc;
char p[120];

int main() {
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; i++) {
        scanf("%s", p);
        for(int j=0; j<m; j++){
            if(p[j] == 'B') {
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d", sx / cc, sy / cc);
    return 0;
}


#include<cstdio>
using namespace std;
int m, n, sx, sy, cc;
char p[120][120];

int main(){
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++){
        scanf("%s", p[i] + 1);
        for(int j=1; j<=n; j++){
            if(p[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


#include<cstdio>

int n, m, sx, sy, cc;
char s[120][120];
int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%s", s[i] + 1);
        for(int j=1; j<=m; j++){
            if(s[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


#include<cstdio>

int n, m, sx, sy, cc;
char s[120][120];
int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%s", s[i] + 1);
        for(j=1; j<=m; j++){
            if(p[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


#include<cstdio>

int n, m, sx, sy, cc;
char s[120][120];
int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=n; i++){
        scanf("%s", s[i] = 1);
        for(j=1; j<=m; j++){
            if(p[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


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

int n, m, sx, sy, cc;
char p[120];

int main() {
    scanf("%d%d", &n, &m);
    for(int i=0; i<n; i++) {
        scanf("%s", p);
        for(int j=0; j<m; j++){
            if(p[j] == 'B') {
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d", sx / cc, sy / cc);
}


#include<cstdio>
using namespace std;

int m, n, sx, sy, cc;
char p[120][120];

int main(){
    scanf("%d %d ", &m, &n);
    for(int i=1; i<= m; i++){
        scanf("%s", p[i] + 1);
        for(int j=0; j<=n; j++){
            if(p[i][j] == 'B'){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


#include<cstdio>
using namespace std;

int m, n, sx, sy, cc;
char p[120][120];

int main(){
    scanf("%d %d", &m, &n);
    for(int i=1; i<=m; i++){
        scanf("%s", p[i] + 1);
        for(int j=1; j<=n; j++){
            if(p[i][j] == b){
                sx += i;
                sy += j;
                cc++;
            }
        }
    }
    printf("%d %d\n", sx / cc, sy / cc);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	int y=sqrt(B);

	int b=0;

	for(int i=0; i<n; i+=1){

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				b+=1;

				if(b==y){

					cout<<i+1<<" "<<j+1;

					break;
				}
			}
		}

		if(b==y){

			break;
		}
	}
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	int y=sqrt(B);

	int b=0;

	for(int i=0; i<n; i+=1){

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				b+=1;

				if(b==y){

					cout<<i<<" "<<j;

					break;
				}
			}
		}

		if(b==y){

			break;
		}
	}
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	if(B&1){

		B=(B/2)+1;
	}

	else{

		B=(B/2);
	}

	int b=0;

	for(int i=0; i<n; i+=1){

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				b+=1;

				if(b==B){

					cout<<i+1<<" "<<j+1;

					break;
				}
			}
		}

		if(b==B){

			break;
		}
	}
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	int y=sqrt(B);

	int x=0,i,j,k=0;

	for(i=0; i<n; i+=1){

		for(j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				x+=1;

				if(x==y){

					k=1;

					break;
				}
			}
		}

		if(k==1){

			break;
		}
	}

	if((n+m)&1){

		cout<<i+1<<" "<<j;
	}

	else{

		cout<<i<<" "<<j;
	}
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	int y=sqrt(B);

	int x=0,i,j,k=0;

	for(i=0; i<n; i+=1){

		for(j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				x+=1;

				if(x==y){

					k=1;

					break;
				}
			}
		}

		if(k==1){

			break;
		}
	}

	if((n+m)%2==0){

		cout<<i<<" "<<j;
	}

	else{

		cout<<i+1<<" "<<j;
	}
}


#include<bits/stdc++.h>

using namespace std;

int main(){

	int n,m;

	cin>>n>>m;

	string str[n];

	int B=0;

	for(int i=0; i<n; i+=1){

		cin>>str[i];

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				B+=1;
			}
		}
	}

	int y=sqrt(B);

	int r,c;

	for(int i=0; i<n; i+=1){

		for(int j=0; j<m; j+=1){

			if(str[i][j]=='B'){

				y+=1;

				if(B==y){

					r=i;

					c=j;

					break;
				}
			}
		}

		if(B==y){

			break;
		}
	}

	cout<<r+1<<" "<<c;
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[100];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B')
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 2;
	int BLACKROW = 2;
	int STARTBR;
	int STARTBC;
	string TABLE[115];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B+1] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A+1][B] == 'B')
				{
					BLACKROW++;
					A++;
				}

				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[115];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B')
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[116];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B')
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[101];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B')
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[115];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B' && B < COL)
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B' && A < ROW)
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[115];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B' && B <= COL)
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B' && A <= ROW)
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2) << endl;
				return 0;
			}
		}
	}
}


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

int main (void)
{
	int A;
	int B;
	int ROW;
	int COL;
	int BLACKCOL = 1;
	int BLACKROW = 1;
	int STARTBR;
	int STARTBC;
	string TABLE[116];

	cin >> ROW >> COL;

	for (A = 0; A < ROW; A++)
	{
		cin >> TABLE[A];
	}

	for (A = 0; A < ROW; A++)
	{
		for (B = 0; B < COL; B++)
		{
			if (TABLE[A][B] == 'B') {
				STARTBR = A;
				STARTBC = B;

				while (TABLE[A][B] == 'B')
				{
					BLACKCOL++;
					B++;
				}

				while (TABLE[A][B-1] == 'B')
				{
					BLACKROW++;
					A++;
				}
				cout << STARTBR + (BLACKROW/2) << " " << STARTBC + (BLACKCOL/2);
				return 0;
			}
		}
	}
}


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

using namespace std;

vector <vector <char>> t;

int main() {
    long long n, m, b_start_x = 0, b_start_y = 0, ans_y = -1, ans_x = -1;
    cin >> n >> m;
    t.resize(n);
    bool w_black_x = true, w_black_y = true, r_black = false;
    for (int i = 0; i < n; ++i) {
        t[i].resize(m);
        r_black = true;
        for (int j = 0 ; j < m; ++j) {
            cin >> t[i][j];
            if (t[i][j] == 'B') {
                r_black = false;
            }
            if (t[i][j] == 'B' && w_black_x == true) {
                w_black_x = false;
                b_start_x = i;
            }
            if (t[i][j] == 'B' && w_black_y == true) {
                w_black_y = false;
                b_start_y = j;
            }
            if (t[i][j] == 'W' && w_black_y == false && ans_y == -1) {
                ans_y = (j - b_start_y) / 2 + b_start_y;
            }
        }
        if (w_black_y == false && ans_y == -1) {
            ans_y = (m - 1 - b_start_y) / 2 + b_start_y;
        }
        if (r_black) {
            ans_x = (i - 1 - b_start_x) / 2 + b_start_x;
        }
    }

    cout << ans_x + 1 << " " << ans_y + 1 << endl;

    return 0;
}


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

using namespace std;

vector <vector <char>> t;

int main() {
    long long n, m, b_start_x = 0, b_start_y = 0, ans_y = -1, ans_x = -1;
    cin >> n >> m;
    t.resize(n);
    bool w_black_x = true, w_black_y = true, r_black = false;
    for (int i = 0; i < n; ++i) {
        t[i].resize(m);
        r_black = true;
        for (int j = 0 ; j < m; ++j) {
            cin >> t[i][j];
            if (t[i][j] == 'B') {
                r_black = false;
            }
            if (t[i][j] == 'B' && w_black_x == true) {
                w_black_x = false;
                b_start_x = i;
            }
            if (t[i][j] == 'B' && w_black_y == true) {
                w_black_y = false;
                b_start_y = j;
            }
            if (t[i][j] == 'W' && w_black_y == false && ans_y == -1) {
                ans_y = (j - b_start_y) / 2 + b_start_y;
            }
        }
        if (w_black_y == false && ans_y == -1) {
            ans_y = (m - 1 - b_start_y) / 2 + b_start_y;
        }
        if (w_black_x == false && r_black) {
            ans_x = (i - 1 - b_start_x) / 2 + b_start_x;
        }
    }
    if (ans_x == -1) {
        ans_x = (n - 1 - b_start_x) / 2 + b_start_x;
    }

    cout << ans_x + 1 << " " << ans_y + 1 << endl;

    return 0;
}


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

using namespace std;

vector <vector <char>> t;

int main() {
    long long n, m, b_start_x = 0, b_start_y = 0, ans_y = -1, ans_x = -1;
    cin >> n >> m;
    t.resize(n);
    bool w_black_x = true, w_black_y = true, r_black = false;
    for (int i = 0; i < n; ++i) {
        t[i].resize(m);
        r_black = true;
        for (int j = 0 ; j < m; ++j) {
            cin >> t[i][j];
            if (t[i][j] == 'B') {
                r_black = false;
            }
            if (t[i][j] == 'B' && w_black_x == true) {
                w_black_x = false;
                b_start_x = i;
            }
            if (t[i][j] == 'B' && w_black_y == true) {
                w_black_y = false;
                b_start_y = j;
            }
            if (t[i][j] == 'W' && w_black_y == false && ans_y == -1) {
                ans_y = (j - b_start_y) / 2 + b_start_y;
            }
        }
        if (w_black_y == false && ans_y == -1) {
            ans_y = (m - 1 - b_start_y) / 2 + b_start_y;
        }
        if (r_black) {
            ans_x = (i - 1 - b_start_x) / 2 + b_start_x;
        }
    }
    if (ans_x == -1) {
        ans_x = (n - 1 - b_start_x) / 2 + b_start_x;
    }

    cout << ans_x + 1 << " " << ans_y + 1 << endl;

    return 0;
}


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

using namespace std;

vector <vector <char>> t;

int main() {
    long long n, m, b_start_x = 0, b_start_y = 0, ans_y = -1, ans_x = -1;
    cin >> n >> m;
    t.resize(n);
    bool w_black_x = true, w_black_y = true, r_black = false;
    for (int i = 0; i < n; ++i) {
        t[i].resize(m);
        r_black = true;
        for (int j = 0 ; j < m; ++j) {
            cin >> t[i][j];
            if (t[i][j] == 'B') {
                r_black = false;
            }
            if (t[i][j] == 'B' && w_black_x == true) {
                w_black_x = false;
                b_start_x = i;
            }
            if (t[i][j] == 'B' && w_black_y == true) {
                w_black_y = false;
                b_start_y = j;
            }
            if (t[i][j] == 'W' && w_black_y == false && ans_y == -1) {
                ans_y = (j - b_start_y) / 2 + b_start_y;
            }
        }
        if (w_black_y == false && ans_y == -1) {
            ans_y = (m - 1 - b_start_y) / 2 + b_start_y;
        }
        if (w_black_x == false && r_black && ans_x == -1) {
            ans_x = (i - 1 - b_start_x) / 2 + b_start_x;
        }
    }
    if (ans_x == -1) {
        ans_x = (n - 1 - b_start_x) / 2 + b_start_x;
    }

    cout << ans_x + 1 << " " << ans_y + 1 << endl;

    return 0;
}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    vector<int> alternate(2*n,-1);
    int fill_pos = 0;
    char next_char = s[0];
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    next_char = (next_char == '1') ? '0' : '1';
    fill_pos = 1;
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    alternate.erase(find_if(alternate.rbegin(),alternate.rend(),[](int i) { return i != -1 ;}).base(),alternate.end());
    // for (auto & i : alternate) cout << i << ' ';
    // cout << endl;

    vector<int> ans(n);
    int group = 1;
    for (int i = 0 ; i < (int)alternate.size()-1 ; i++)
    {
      if (alternate[i] != -1) ans[alternate[i]] = group;
      if (alternate[i+1] < alternate[i] ) {
        group ++;
      }
    }

    if (alternate[alternate.size()-1] < alternate[alternate.size()-2]) group++;
    ans[n-1] = group;
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout<< endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    stack<int> group_end_one;
    stack<int> group_end_zero;
    vector<int> ans(n);
    int group = 0;
    for (int i = 0 ; i < n ; i++) {
      int cur_ans = 0;
      if (s[i] == '0') {
        if (group_end_one.size() == 0) {
          group_end_zero.push(++group);
          cur_ans = group;
        } else {
          cur_ans = group_end_one.top();
          group_end_one.pop();
          group_end_zero.push(cur_ans);
        }
      } else {
          if (group_end_zero.size() == 0) {
          group_end_one.push(++group);
          cur_ans = group;
        } else {
          cur_ans = group_end_zero.top();
          group_end_zero.pop();
          group_end_one.push(cur_ans);
        }
      }
      ans[i] = cur_ans;
    }
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout << endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  // freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    vector<int> alternate(2*n,-1);
    int fill_pos = 0;
    char next_char = s[0];
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    next_char = (next_char == '1') ? '0' : '1';
    fill_pos = 1;
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    alternate.erase(find_if(alternate.rbegin(),alternate.rend(),[](int i) { return i != -1 ;}).base(),alternate.end());
    // for (auto & i : alternate) cout << i << ' ';
    // cout << endl;

    vector<int> ans(n);
    int group = 1;
    for (int i = 0 ; i < (int)alternate.size()-1 ; i++)
    {
      if (alternate[i+1] < alternate[i] ) {
        group ++;
      }
      if (alternate[i] != -1) ans[alternate[i]] = group;
    }

    if (alternate[alternate.size()-1] < alternate[alternate.size()-2]) group++;
    ans[n-1] = group;
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout<< endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    vector<int> visited(n,0);
    int cnt = 0;
    auto dfs = [&] (int cur) {
      auto dfs_impl = [&](int cur, char cur_c,auto &dfs_ref) {
        if (0) return ; // for type deduction
        visited[cur] = cnt;
        for (int i = cur + 1; i < n ; i++) {
          if (s[i] != cur_c && !visited[i]) {
            return dfs_ref(i,s[i],dfs_ref);
          }
        }
        return;
      };
      dfs_impl(cur,s[cur],dfs_impl);
    };
    for (int i = 0 ; i < n ; i++) {
      if (!visited[i]) {
        cnt ++;
        dfs(i);
      }
    }

    cout << cnt << endl;
    for (auto & i : visited) cout << i << " ";
    cout << endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    if (n == 1) {
      cout << 1 << endl << 1 << endl;
      continue;
    }
    vector<int> alternate(2*n,-1);
    int fill_pos = 0;
    char next_char = s[0];
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    next_char = (next_char == '1') ? '0' : '1';
    fill_pos = 1;
    for (int i = 0 ; i < n ; i++)
    {
      if (s[i] == next_char) {
        alternate[fill_pos] = i;
        fill_pos += 2;
      }
    }
    alternate.erase(find_if(alternate.rbegin(),alternate.rend(),[](int i) { return i != -1 ;}).base(),alternate.end());
    // for (auto & i : alternate) cout << i << ' ';
    // cout << endl;

    vector<int> ans(n);
    int group = 1;
    for (int i = 0 ; i < (int)alternate.size()-1 ; i++)
    {
      if (alternate[i] != -1) ans[alternate[i]] = group;
      if (alternate[i+1] < alternate[i] ) {
        group ++;
      }
    }

    // if (alternate[alternate.size()-1] < alternate[alternate.size()-2]) group++;
    ans[alternate[alternate.size()-1]] = group;
    cout << group << endl;
    for (auto & i : ans) cout << i << " ";
    cout<< endl;
  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    set<int> ones;
    set<int> zeros;
    for ( int i = 0 ; i < n ; i++)
    {
      if (s[i] == '0') zeros.insert(i);
      else ones.insert(i);
    }

    int group = 1;
    vector<int> ans (n);
    ans[0] = group;
    char last = s[0];
    int last_idx = 0;
    if (last == '0') zeros.erase(zeros.begin());
    else ones.erase(ones.begin());
    while (ones.size() > 0 || zeros.size() >0)
    {
      if (last == '1' && zeros.size() <=0 ) break;
      else if (last == '0' && ones.size() <=0 ) break;
      if (last == '0'){
         auto next = ones.upper_bound(last_idx);
        if (next!= ones.end()){
          last_idx = *next;
          last = '1';
          ans[last_idx] = group;
          ones.erase(next);
        } else {
          group ++;
          if (*ones.begin() < *zeros.begin()) {
            last_idx = *ones.begin()-1;
            last = '0';
          } else {
            last_idx = *zeros.begin()-1;
            last = '1';
          }
        }
      }
      else
      {
        auto next = zeros.upper_bound(last_idx);
        if (next != zeros.end()){
          last_idx = *next;
          last = '0';
          ans[last_idx] = group;
          zeros.erase(next);
        } else {
          group ++;
          if (*ones.begin() < *zeros.begin()) {
            last_idx = *ones.begin()-1;
            last = '0';
          } else {
            last_idx = *zeros.begin()-1;
            last = '1';
          }
        }
      }
    }
    group ++;
    if (ones.size() > 0) {
      for (auto & i : ones) {
        ans[i] = group;
        group ++;
      }
    } else if (zeros.size() > 0) {
        for (auto & i : zeros) {
          ans[i] = group;
          group ++;
      }
    }
    cout << --group << endl;
    for (auto & i : ans) cout << i << " ";
    cout << endl;

  }

}


#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
#include <limits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
//   freopen("CF/input.in","r",stdin);
  int t; cin >> t;
  while (t--) {
    int n; cin >> n;
    string s ; cin >> s;
    set<int> ones;
    set<int> zeros;
    for ( int i = 0 ; i < n ; i++)
    {
      if (s[i] == '0') zeros.insert(i);
      else ones.insert(i);
    }

    int group = 1;
    vector<int> ans (n);
    ans[0] = group;
    char last = s[0];
    int last_idx = 0;
    if (last == '0') zeros.erase(zeros.begin());
    else ones.erase(ones.begin());
    while (ones.size() >= 0 || zeros.size() >=0)
    {
      if (last == '0' && ones.size()<= 0) break;
      else if (last == '1' && zeros.size() <=0) break;
      if (last == '0' && *ones.begin() > last_idx)
      {
        last_idx = *ones.begin();
        last = '1';
        ans[*ones.begin()] = group;
        ones.erase(ones.begin());
      } else if (last == '1' && *zeros.begin() > last_idx)
      {
        last_idx = *zeros.begin();
        last = '0';
        ans[*zeros.begin()] = group;
        zeros.erase(zeros.begin());
      } else
      {
        group ++;
        if (*ones.begin() < *zeros.begin())
        {
          last_idx = *ones.begin();
          last = '1';
          ans[*ones.begin()] = group;
          ones.erase(ones.begin());
        } else
        {
          last_idx = *zeros.begin();
          last = '0';
          ans[*zeros.begin()] = group;
          zeros.erase(zeros.begin());
        }
      }
    }
    group ++;
    if (ones.size() > 0)
    {
      for (auto & pos : ones)
      {
        ans[pos] = group ++;
      }
    } else if (zeros.size() > 0)
    {
      for (auto & pos : zeros)
      {
        ans[pos] = group ++;
      }
    }

    cout << --group << endl;
    for (auto & i : ans)
      cout << i << " " ;
    cout << endl;

  }

}