#include <bits/stdc++.h>
#define endl "\n"
#define io_boost() std::ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int M=1000000007;

void solve(){
	int n, m;
	cin>>n>>m;

	int cnt=0;
	rep(i, n){
		string s;
		cin>>s;
		for(char c : s) if(c=='#') cnt++;
	}

	int ans=1;
	rep(_, cnt) ans=ans*2%M;
	if(cnt==n*m) ans--;

	cout<<ans<<endl;
}

int main(){
	io_boost();
	int t;
	cin>>t;
	rep(_, t) solve();
	return 0;
}

