//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \###################\
//   \###################\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.
 
#ifdef local
#include <bits/extc++.h>
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(args...) qqbx(#args, args)
using ost = std::ostream;
#define DESTL(STL, BEG, END, OUT) \
    template <typename ...T> ost& operator<<(ost &O, std::STL<T...> v) { int f=0; for(auto x: v) O << (f++ ? ", " : BEG) << OUT; return O << END; }
DESTL(deque, "[", "]", x); DESTL(vector, "[", "]", x);
DESTL(set, "{", "}", x); DESTL(multiset, "{", "}", x); DESTL(unordered_set, "{", "}", x);
DESTL(map , "{", "}", x.first << ":" << x.second); DESTL(unordered_map , "{", "}", x.first << ":" << x.second);
template <typename U, typename V> ost& operator<<(ost &O, std::pair<U,V> p) { return O << '(' << p.first << ',' << p.second << ')'; }
template <typename T, size_t N> ost& operator<<(ost &O, std::array<T,N> a) { int f=0; for(T x: a) O << (f++ ? ", " : "[") << x; return O << "]"; }
template <typename T, size_t ...I> ost& prtuple(ost &O, T t, std::index_sequence<I...>) { return (..., (O << (I ? ", " : "(") << std::get<I>(t))), O << ")"; }
template <typename ...T> ost& operator<<(ost &O, std::tuple<T...> t) { return prtuple(O, t, std::make_index_sequence<sizeof...(T)>()); }
template <typename ...T> void qqbx(const char *s, T ...args) {
    int cnt = sizeof...(T);
    (std::cerr << "\033[1;32m(" << s << ") = (" , ... , (std::cerr << args << (--cnt ? ", " : ")\033[0m\n")));
}
#else
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/extc++.h>
#include <bits/stdc++.h>
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define get_pos(v,x) int(lower_bound(begin(v),end(v),x)-begin(v))
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
#define pb emplace_back
#define ff first
#define ss second
#define mem(v,x) memset(v,x,sizeof v)
 
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
template <typename T> using max_heap = std::priority_queue<T,vector<T>,less<T> >;
template <typename T> using min_heap = std::priority_queue<T,vector<T>,greater<T> >;
template <typename T> using rbt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-7;
constexpr ll N = 200025, INF = 1e18, MOD = 1000000007, K = 14699, inf = 1e9;
constexpr inline ll cdiv(ll x, ll m) { return x/m + (x%m ? (x<0) ^ (m>0) : 0); } // ceiling divide
constexpr inline ll modpow(ll e,ll p,ll m=MOD) { ll r=1; for(e%=m;p;p>>=1,e=e*e%m) if(p&1) r=r*e%m; return r; }

map<int,int> mp[N];
int pa[N];
int anc(int x) { return x==pa[x] ? x : pa[x]=anc(pa[x]); }
void join(int x, int y) {
    if((x=anc(x)) == (y=anc(y))) return;
    if(mp[x].size() < mp[y].size()) {
        for(auto [a, b]: mp[x])
            mp[y][a] += b;
        mp[x].clear();
        pa[x] = y;
    } else {
        for(auto [a, b]: mp[y])
            mp[x][a] += b;
        mp[y].clear();
        pa[y] = x;
    }
}
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, q;
    cin >> n >> q;
    for(int i = 0; i < n; i++) {
        int c;
        cin >> c;
        mp[i][c] = 1;
    }
    for(int i = 0; i < n; i++) pa[i] = i;
    for(int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if(t == 1) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            join(a, b);
        } else if(t == 2) {
            int x, y;
            cin >> x >> y;
            --x;
            debug(x, mp[anc(x)]);
            cout << mp[anc(x)][y] << '\n';
        }
    }
}

#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=2005;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
const ll mod = 1e9 + 7;
int n,m,l[N][N],r[N][N],u[N][N],d[N][N];
ll bin[N*N];
char s[N][N];
void solve()
{
	cin >> n >> m;
	for(int i=1; i<=n; i++) scanf("%s", s[i]+1);
	bin[0] = 1;
	for(int i=1; i<=4000000; i++) bin[i] = bin[i-1] * 2 % mod;
	ll ans = 0, k = 0;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j] != '.') {
				l[i][j] = r[i][j] = u[i][j] = d[i][j] = 0;
				continue;
			}
			k++;
			if(s[i][j-1] == '.') l[i][j] = l[i][j-1] + 1; else l[i][j] = 1;
			if(s[i-1][j] == '.') u[i][j] = u[i-1][j] + 1; else u[i][j] = 1;
		}
	}
	for(int i=n; i>=1; i--) {
		for(int j=m; j>=1; j--) {
			if(s[i][j] != '.') {
				l[i][j] = r[i][j] = u[i][j] = d[i][j] = 0;
				continue;
			}
			if(s[i][j+1] == '.') r[i][j] = r[i][j+1] + 1; else r[i][j] = 1;
			if(s[i+1][j] == '.') d[i][j] = d[i+1][j] + 1; else d[i][j] = 1;
		}
	}
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			if(s[i][j] != '.') {
				continue;
			}
			int s = (r[i][j] + l[i][j] - 1) + (u[i][j] + d[i][j] - 1) - 1;
			ans += bin[k - s] * (bin[s] - 1 + mod) % mod;
			ans %= mod;
		}
	}
	cout << ans;
}
int main()
{
	int T = 1;
	while(T--) solve();
}