#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
#define f first
#define s second
#define pb push_back
#define sz(x) ((int) x.size())
#define all(x) x.begin(), x.end()
const int N = 300300;
const int mod = 1e9 + 7;
int binpow(int a,int b) {
	int r = 1;
	for(; b; b >>= 1, a = (a * 1ll * a) % mod) if(b & 1) {
		r = (r * 1ll * a) % mod;
	}
	return r;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int t; cin >> t;
	while(t--) {
		int n, m; cin >> n >> m;
		vector<string> a(n);
		int cnt = 0;
		for(int i = 0; i < n; i++) {
			cin >> a[i];
			cnt += count(a[i].begin(), a[i].end(), '#');
		}
		cout << binpow(2, cnt) - (cnt == n * m) << '\n';
	}
}