#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
  
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const ll inf = 1e18;
const int i_inf = 1e9;
const ll mod = 1e9+7;
 
mt19937 _rand(time(NULL));
const int mxn = 5e5+5;
 

ll modpow(ll x, ll n){
	if(n == 0) return 1%mod;
	ll u = modpow(x, n/2);
	u = (u * u) % mod;
	if(n % 2) u = (u * x) % mod;
	return u;
}

void solve(){
	int n, m;
	cin >> n >> m;
	char c;
	int cn = 0;
	fr(i, 0, n){
		fr(j ,0, m){
			cin >> c;
			if(c == '#') cn ++;
		}
	}
	if(cn < n*m) cout<<modpow(2, cn)<<endl;
	else{
		ll a = modpow(2, cn)-1;
		if(a < 0) a += mod;
		cout<<a<<endl;
	}
}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
}
 
