#include <bits/stdc++.h>
#include<string>
#include<vector> 
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> o_set;

typedef long double ld;
typedef long long int ll;
#define int long long
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

#define FAST   ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define INF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define se second 
#define loop(i,n) for(ll i=0;i<n;i++)
#define leep(i,n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(), v.end()
#define remove_dulpicate(d)    d.resize(unique(all(d))-d.begin())

ll power(ll a,ll b){
   if(b==0) return 1LL;
   ll p=power(a,b/2);
   p=p*p%MOD;
   return (b&1)?p*a%MOD:p;
}

int32_t main() {

   FAST
   int tt;
   cin>>tt;
   while(tt--)
   {
      int n,m,cnt=0;
      cin>>n>>m;
      
      char mat[n][m];
      
      for(int i=0;i<n;i++){
         string s;
         cin>>s;
         cnt+=count(all(s),'#'); 
      }
      
      int ans=power(2,cnt);
      
      if(cnt==n*m){
         ans=(ans-1+MOD)%MOD;
      }
      cout<<ans<<"\n";
   }
   //check constraints
	
	return 0;
}
