#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(4e5)+10;
int n,fa[maxn],dis[maxn],dep[maxn];
vector<int> g[maxn];
int lg[maxn];
int mx,son[maxn];
void dfs(int u,int p) {
	dis[u]=dis[p]+1; fa[u]=p;
	for (int v : g[u]) if (v!=p) dfs(v,u);
	if (!mx||dis[u]>dis[mx]) mx=u;
}
int st[maxn][20];
int dfn[maxn],tot,idx,euler[maxn],pos[maxn],ans[maxn];
void dfs2(int u,int p) {
	dfn[++idx]=u;
	for (int v : g[u]) if (v!=p&&v!=son[u]) dfs2(v,u);
	if (son[u]) dfs2(son[u],u);
}
int MN(int x,int y) {
    if (dep[x]<dep[y]) return x;
    return y;
}
int lca(int x,int y) {
    x=pos[x],y=pos[y];
    if (x>y) swap(x,y);
    int j=lg[y-x+1];
    return MN(st[x][j],st[y-(1<<j)+1][j]);
}
int DIS(int x,int y) {
    return dep[x]+dep[y]-2*dep[lca(x,y)];
}
void pre(int u,int p) {
    dep[u]=dep[p]+1;
    euler[++tot]=u; pos[u]=tot;
    for (int v : g[u]) if (v!=p) {
        pre(v,u);
        euler[++tot]=u;
    }
}
int main() {
	//freopen("1.txt","r",stdin);
    for (int i=2;i<maxn;i++) lg[i]=lg[i>>1]+1;
	read(n); int x,y,z;
	for (int i=1;i<n;i++) {
		read(x),read(y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	pre(1,0);
	for (int i=1;i<=tot;i++) st[i][0]=euler[i];
    for (int j=1;j<=19;j++)
    for (int i=1;i+(1<<j)-1<=tot;i++)
        st[i][j]=MN(st[i][j-1],st[i+(1<<(j-1))][j-1]);
	mx=0; dfs(1,0); x=mx;
	mx=0; dfs(x,0); y=mx;
	z=y;
	while (fa[z]) son[fa[z]]=z,z=fa[z];
	dfs2(x,0);
	ans[x]=1;
	for (int i=2;i<=n;i++)
		ans[dfn[i]]=ans[dfn[i-1]]+DIS(dfn[i],dfn[i-1]);
	for (int i=1;i<=n;i++) printf("%d ",ans[i]); puts("");
	return 0;
}
/*
  REMEMBER:
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Array size? Integer overflow? Time complexity? Memory usage? Precision error?
*/
//#pragma GCC target("avx,avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define mem(a,b)   memset(a,b,sizeof(a))
#define en         cout<<endl;
#define pb         push_back
#define gcd(n,m)   __gcd(n,m)
#define lcm(n,m)   ((n)/__gcd(n,m))*(m)
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(i,a,b)   for(ll i=a;i<b;i++)
#define r(i,a,b)   for(ll i=a;i>=b;i--)
#define all(x)     (x).begin(),(x).end()
#define allr(x)    (x).rbegin(),(x).rend()
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long
#define PI         2*acos(0.0)
#define MAXN       3*100000
ll n,m,k,g,mx,mn,res,c,x,y,z,w,p,q,r,l,s,t;

void solve()
{
    ci>>n>>m>>x>>y;
    char a[n][m];
    f(i,0,n) f(j,0,m) ci>>a[i][j];
    x--;y--;
    ll i=y;
    c=0;
    while(a[x][i]=='.' and i>=0)
    {
        c++;
        i--;
    }
    i=y+1;
    while(a[x][i]=='.' and i<m)
    {
        c++;
        i++;
    }
    i=x-1;
    while(a[i][y]=='.' and i>=0)
    {
        c++;
        i--;
    }
    i=x+1;
    while(a[i][y]=='.' and i<n)
    {
        c++;
        i++;
    }
    co<<c<<endl;
}

int main()
{
        
//#ifdef LOCAL
        //freopen("input.txt","r",stdin);
        //freopen("output.txt","w",stdout);
//#endif
        auto start_time = clock();
        cerr << setprecision(3) << fixed;
        cout << setprecision(10) << fixed;
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        // ci>>t;
        t=1;
        for(ll ca=0;ca<t;ca++)
        {
            solve();
        }
//#ifdef LOCAL
        auto end_time = clock();
        cerr<< "Execution time: "<<(end_time-start_time)*(int)1e3/CLOCKS_PER_SEC<<" ms\n";
//#endif
}