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

typedef long long ll;

const int mod = 1e9 + 7;

ll modPower(ll x, ll y) {
    ll ret = 1;
    while(y) {
        if(y&1) ret = (ret * x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return ret;
}

int main() {
    int T;
    cin>>T;
    while(T--) {
        int n, m;
        cin>>n>>m;
        int hash = 0;
        for(int i = 0; i < n; ++i) {
            string s;
            cin>>s;
            for(char x : s) if(x == '#')++hash;
        }
        ll ans = modPower(2, hash);
        if(hash == n*m) {
            ans = (ans - 1 + mod) % mod;
        }
        
        cout<< ans << endl;
    }
}