#include<bits/stdc++.h>
#define ll long long
#define sortall(a) sort(a.begin(),a.end())
#define endl "\n"
#define F first
#define S second
#define reall(a) reverse(a.begin(),a.end())
#define lb long double
#define forr(i,a,b) for (int i = a;i<b;i++)
#define forn(i,a,b) for(int i = a;i>=b;i--)
using namespace std;
typedef pair<int,int> ii;
typedef pair<long long,long long> LL;
const ll base = 31;
int xx[]= {0,0,1,-1};
int yy[] = {-1,1,0,0};
int zz[] ={0,0,0,0,1,-1};
string step = "URDL";
const int maxn = 1000+2;
const ll mod = 1e9+7;
ll Pow(ll a, ll b){ll res = 1;if(b <=0)return 1;while(b>0){if(b%2){res=(res%mod *a%mod);res%=mod;}a=(a%mod*a%mod)%mod;b/=2;}return res%mod;}
ll maybe[] = {11,111,1111,11111,111111,1111111,11111111,111111111};



void solve(){
    ll cnt = 0;
    bool ok = true;
    int n,m; cin >> n >> m;
    for(int i = 0 ;i<n;i++){
        string s; cin >> s;
        for(char c : s){
            cnt += (c == '#');
            if(c == '0'){
                ok = false;
            }
        }
    }
    ll res = 1;
    for(int i = 0 ;i<cnt;i++){
        res = (res % mod)*(2%mod);
        res %= mod;
    }
    cout << res - ok << endl;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    /*if (fopen("hight.inp", "r")) {
        freopen("hight.INP","r",stdin);
        freopen("hight.OUT","w",stdout);
    } */
    int t =1;
    cin >> t;
    while(t--){
        solve();
    }
}
