#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}

vl p(200005);
vector <unordered_map<ll, ll>> pp(200005);
vl siz(200005, 1);

ll get(ll u) {
	return p[u] = (p[u] == u) ? u : get(p[u]);
}

void unions(ll a, ll b) {
	a = get(a);
	b = get(b);
	//cout << a << " " << b << "\n";
	if (a == b)
		return;
	if (siz[a] > siz[b])
		swap(a, b);
	for (auto i : pp[a]) {
		//cout << i.ff << " " << i.ss << "\n";
		pp[b][i.ff] += i.ss;
	}
	p[a] = b;
	siz[b] += siz[a];
}



int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	t = 1;
	//cin >> t;
	while (t--) {
		ll n;
		cin >> n;
		ll q;
		cin >> q;
		for (ll i = 1; i <= n; i++)
			p[i] = i;

		for (ll i = 1; i <= n; i++) {
			ll d;
			cin >> d;
			pp[i][d] = 1;
		}


		while (q--) {
			ll x, y, z;
			cin >> z;
			cin >> x >> y;
			if (z == 1) {
				unions(x, y);
			}
			else {
				x = get(x);
				cout << pp[x][y] << "\n";
			}
		}
	}
}

#include<bits/stdc++.h> 
using namespace std;
namespace Sakurajima_Mai{
    #define ms(a) memset(a,0,sizeof(a))
    #define repi(i,a,b) for(int i=a,bbb=b;i<=bbb;++i)//attention reg int or reg ll ?
    #define repd(i,a,b) for(int i=a,bbb=b;i>=bbb;--i)
    #define reps(s) for(int i=head[s],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
    #define ce(i,r) i==r?'\n':' '
    #define pb push_back 
    #define all(x) x.begin(),x.end()
    #define gmn(a,b) a=min(a,b)
    #define gmx(a,b) a=max(a,b)
    #define fi first
    #define se second                         
    typedef long long ll;
    typedef unsigned long long ull;
    typedef double db;
    const int infi=1e9;//infi较大，注意涉及inf相加时爆int
    const ll infl=4e18;
    inline ll ceil_div(ll a,ll b){ return (a+b-1)/b; }
    inline ll pos_mod(ll a,ll b){ return (a%b+b)%b; }
    //std::mt19937 rnd(time(0));//std::mt19937_64 rnd(time(0));
}
using namespace Sakurajima_Mai;
namespace Fast_Read{
    inline int qi(){
        int f=0,fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline ll ql(){
        ll f=0;int fu=1; char c=getchar();
        while(c<'0'||c>'9'){ if(c=='-')fu=-1; c=getchar(); }
        while(c>='0'&&c<='9'){ f=(f<<3)+(f<<1)+c-48; c=getchar(); }
        return f*fu;
    }
    inline db qd(){
        char c=getchar();int flag=1;double ans=0;
        while((!(c>='0'&&c<='9'))&&c!='-') c=getchar();
        if(c=='-') flag=-1,c=getchar();
        while(c>='0'&&c<='9') ans=ans*10+(c^48),c=getchar();
        if(c=='.'){c=getchar();for(int Bit=10;c>='0'&&c<='9';Bit=(Bit<<3)+(Bit<<1)) ans+=(double)(c^48)*1.0/Bit,c=getchar();}
        return ans*flag;
    }
}
namespace Read{
    #define si(a) scanf("%d",&a)
    #define sl(a) scanf("%lld",&a)
    #define sd(a) scanf("%lf",&a)
    #define ss(a) scanf("%s",a)
    #define rai(x,a,b) repi(i,a,b) x[i]=qi()
    #define ral(x,a,b) repi(i,a,b) x[i]=ql()
}
namespace Out{
    #define pi(x) printf("%d",x)
    #define pl(x) printf("%lld",x)
    #define ps(x) printf("%s",x)
    #define pc(x) printf("%c",x)
    #define pe() puts("")
}
namespace DeBug{
    #define MARK false
    #define DB if(MARK) 
    #define pr(x) cout<<#x<<": "<<x<<endl
    #define pra(x,a,b) cout<<#x<<": "<<endl; \
            repi(i,a,b) cout<<x[i]<<" ";     \
            puts("");   
    #define FR(a) freopen(a,"r",stdin)
    #define FO(a) freopen(a,"w",stdout)
}
using namespace Fast_Read;
using namespace Read;
using namespace Out;
using namespace DeBug;
const int MAX_N=1e2+5;
char g[MAX_N][MAX_N];
int main()
{
    int h=qi(),w=qi(),x=qi(),y=qi();
    repi(i,1,h) ss(g[i]+1);
    int cnt=0;
    if(g[x][y]!='#') cnt++;
    repi(i,x+1,h){
        if(g[i][y]=='#') break;
        cnt++;
    }
    repd(i,x-1,1){
        if(g[i][y]=='#') break;
        cnt++;
    }
    repi(i,y+1,w){
        if(g[x][i]=='#') break;
        cnt++;
    }
    repd(i,y-1,1){
        if(g[x][i]=='#') break;
        cnt++;
    }
    pi(cnt),pe();
    return 0;
}