#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define piii pair<int,pii>
#define sp " "
#define nl "\n"
#define all(x) x.begin(),x.end()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long
#define int ll
 
using namespace std;

constexpr int N = 2005;
constexpr int INF = 1e9+5;
constexpr int mod = 1e9+7;

int n,m;
char s[N][N];

int carp(int x,int y){
    return x*y%mod;
}

void solve(){    
    cin >> n >> m;
    int ans=1;
    bool flag=true;
    for(int i=1;i<=n;i++){
        cin >> s[i]+1;
        for(int j=1;j<=m;j++){
            if(s[i][j]=='0')
                flag=false;
            else
                ans=carp(ans,2);
        }
    }
    cout << ans-flag << nl;
}

signed main(){
    #ifdef LOCAL
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    fastio()
    int tt=1;
    cin >> tt; 
    while(tt--)
        solve();
}