#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        int ans = 1;
        bool has = false;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                char c;
                cin >> c;
                if (c == '0') 
                    has = true;
                else 
                    ans = (2LL * ans) % mod;
            }
        }
        if(has) 
            cout << ans << '\n';
        else 
            cout << (ans - 1) << '\n';
    }
    return 0;
}