#include <bits/stdc++.h>

#pragma region ppd
#define ll long long
#define ld long double
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forr(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define foriter(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define endl '\n'
#define INF (ll)(1e9)
#define EPS 1e-9
#define MOD (ll)(1e9 + 7)
#define PI 3.1415926535897932384626433832795
#define set set
#define mset multiset
#define uset unordered_set
#define umset unordered_multiset
#define map map
#define mmap multimap
#define umap unordered_map
#define ummap unordered_multimap
#define FILEIO                        \
	freopen("input.txt", "r", stdin); \
	freopen("output.txt", "w", stdout);

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vll;
typedef vector<vll> vvll;
typedef pair<i64, i64> pll;

template <class T>
bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template <class T>
bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T> void re(T &x) { cin >> x; }
template <class Arg, class... Args> void re(Arg &first, Args &...rest) { re(first); re(rest...); }
template <class T> void re(vector<T> &a) { for0(i, a.size()) re(a[i]); }

template <class T> void pr(T &x) { cout << x << " "; }
template <class Arg, class... Args> void pr(Arg &first, Args &...rest) { pr(first); pr(rest...); }
template <class T> void pr(vector<T> &a) { for0(i, a.size()) pr(a[i]); }


#pragma endregion ppd

//=============================================================================//
vll fact;

void compute_fact(ll n, ll p = MOD) {
	fact.assign(n+1, 1);

	for1(i, n) {
		fact[i] = (i*fact[i-1])%p;
	}
}

ll addmod(ll a, ll b, ll p = MOD) {
	return (a % p + b % p) % p;
}

ll mulmod(ll a, ll b, ll p = MOD) {
	return ((a % p) * (b % p)) % p;
}

ll powmod(ll a, ll b, ll p = MOD){
	a %= p;
	if (a == 0) return 0;
	ll product = 1;
	while(b > 0){
		if (b&1){    // you can also use b % 2 == 1
			product *= a;
			product %= p;
			--b;
		}
		a *= a;
		a %= p;
		b /= 2;    // you can also use b >> 1
	}
	return product;
}
 
ll inv(ll a, ll p = MOD){
	return powmod(a, p-2, p);
}
 
ll nCk(ll n, ll k, ll p = MOD){
	return ((fact[n] * inv(fact[k], p) % p) * inv(fact[n-k], p)) % p;
}
void solve()
{
	ll n,m; re(n,m);
	ll cnt = 0;
	for(int i = 0; i < m*n; i++) {
		char c; cin >> c;
		cnt += c == '#';
	}
	if(cnt == m*n) {
		cout << powmod(2, cnt)-1;
	}
	else cout << powmod(2, cnt);
}

int main()
{
#ifndef ONLINE_JUDGE
	FILEIO
	auto start = chrono::high_resolution_clock::now();
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	//==================================================================================

	int T = 1;
	cin >> T;
	while (T--)
	{
		solve();
		cout << endl;
	}

//==================================================================================
#ifndef ONLINE_JUDGE
	auto finish = chrono::high_resolution_clock::now();

	chrono::duration<double> elapsed = finish - start;
	cout << "\nTime: " << elapsed.count() << " s\n";
#endif

	return 0;
}