#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int long long
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;

// int mod;
int power(int x, int y)
{
    int res = 1LL;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int  n)
{
    return power(n,mod-2)%mod;
}

int isprime(int n){
    if(n<2)return 0;
    int i;
    for(i=2;i*i<=n;i++)
        if(n%i==0)
            return 0;
    return 1;

}
int sq(int n){
    return n*n;

}



// https://codeforces.com/problemset/problem/540/D
// https://codeforces.com/problemset/problem/1107/D

// dp-https://codeforces.com/problemset/problem/19/B


// https://codeforces.com/contest/27/problem/E
// https://codeforces.com/blog/entry/337


int c=0;
void solve(){

    int n,m;
    cin>>n>>m;
    int i;
    c=0;
    for(i=0;i<n;i++){
        string s;
        cin>>s;
        c+=count(all(s),'#');
    }
    int ans=power(2,c);
    if(c==n*m)
        ans--;
    cout<<ans<<"\n";

    

}
int32_t main(){
   fast
    int t=1;
    int tc=0;
     cin>>t; 

    while(t--) 
    {
        tc++;
        // cout<<"Case #"<<tc<<": "
        solve();
    }
}