#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h = 0, w = 0, x = 0, y = 0;
    cin >> h >> w >> x >> y; --x; --y;
    vector<string> s(h);
    for (auto &i : s)
        cin >> i;
    int res = 0;
    for (int i = y; i < w && s[x][i] != '#'; ++i)
        ++res;
    for (int i = y; i >= 0 && s[x][i] != '#'; --i)
        ++res;
    for (int i = x; i < h && s[i][y] != '#'; ++i)
        ++res;
    for (int i = x; i >= 0 && s[i][y] != '#'; --i)
        ++res;
    cout << res - 3;
}
#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
typedef priority_queue <ll> pq;
#define o_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define graph vector<vi>

const ll mod = 1000000007;
const ll INF = (ll)1e18;
const ll MAXN = 1000006;

ll po(ll x, ll n ){ 
    ll ans=1;
     while(n>0){
         if(n&1) ans=(ans*x)%mod;
         x=(x*x)%mod;
         n/=2;
     }
     return ans;
}

vi par(200005);
vector<map<ll, ll> > v;

ll getP(ll s){
    if(par[s]==s) return s;
    else return (par[s]=getP(par[s]));
}

void unite(ll x, ll y){
    ll a=getP(x);
    ll b=getP(y);

    if(a==b) return;

    if(v[a].size()<v[b].size()) swap(a,b);
    par[b]=a;

    for(auto h:v[b]){
        if(v[a].find(h.ff)==v[a].end()) v[a].insert(mp(h.ff,0ll));
        v[a][h.ff]+=h.ss;
    }

    v[b].clear();

}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int T=1;
    //cin >> T;
    while(T--){
        ll n,q;
        cin>>n>>q;

        ll c[n+1];
        rep(i,n) cin>>c[i+1];

        rep(i,200005) par[i]=i;
        v.assign(n+1, map<ll,ll>());

        rep_a(i,1,n+1) v[i].insert(mp(c[i],1ll));

        ll t,x,y;

        rep(i,q){
            cin>>t>>x>>y;
            if(t==1) unite(x,y);
            else{
                t = getP(x);
                if(v[t].find(y)==v[t].end()) cout<<0<<el;
                else cout<<v[t][y]<<el;
            }
        }

    
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}