#line 2 "/home/defineprogram/Desktop/Library/template/template.cpp"
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<ll,ll>
#define len(s) (ll)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr ll inf = 3e18;
#line 2 "main.cpp"

int H,W;
char c[105][105];
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>H>>W;
    rep(i,H)rep(j,W)cin>>c[i][j];
    int ans=0;
    rep(i,H)rep(j,W-1)if(c[i][j]=='.'&&c[i][j+1]=='.')ans++;
    rep(i,H-1)rep(j,W)if(c[i][j]=='.'&&c[i+1][j]=='.')ans++;
    cout<<ans<<"\n";
}

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

int n,q;
int c[200001];
int uf[200001];
vector <pair<int,pair<int,int>>> query;
map <int,int> cnt[200001];
int check[200001];

int find(int x)
{
	if(uf[x] < 0)
	{
		return x;
	}
	return uf[x] = find(uf[x]);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int total = 0;

    memset(check,0,sizeof(check));
    cin >> n >> q;

    for(int i=1;i<=n;i++)
    {
    	cin >> c[i];
    }

    for(int i=0;i<q;i++)
    {
    	int a,b,c;
    	cin >> a >> b >> c;
    	query.push_back(make_pair(a,make_pair(b,c)));
    	if(a==2)
    	{
    		total++;
    		check[c]++;
    	}
    }

    for(int i=1;i<=n;i++)
    {
    	if(check[c[i]]>0)
    	{
    		cnt[i][c[i]] = 1;
    	}
    }
    memset(uf,-1,sizeof(uf));

    for(int i=0;i<q;i++)
    {
    	if(total==0)
    	{
    		break;
    	}
    	if(query[i].first==1)
    	{
    		int u = query[i].second.first;
    		int v = query[i].second.second;
    		int t;
    		if(u > v)
    		{
    			t = u;
    			u = v;
    			v = t;
    		}
    		//u = uf[u];
    		//v = uf[v];
    		u = find(u);
    		v = find(v);
    		if(u!=v)
    		{    		
    			uf[v] = u;
    			//cout << u << ' ' << v << '\n';	
				for(auto it : cnt[v])
				{
					if(check[it.first]==0)
					{
						continue;
					}
					cnt[u][it.first] += it.second;
				}
				cnt[v].clear();
    		}
    	}
    	else
    	{
    		int x = query[i].second.first;
    		int y = query[i].second.second;
    		long long int g = find(x);
    		long long int res = cnt[g][y];
    		cout << res << '\n';
    		check[y]--;
    		total--;
    	}
    }
    return 0;
}