// https://codeforces.com/contest/1536/problem/E
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main()
{
    cin.tie(0)->sync_with_stdio(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        int dem = 0, cnt = 0;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 1; j <= m; ++j)
            {
                char c;
                cin >> c;
                if (c == '0') dem++;
                else cnt++;
            }
        }
        int ans = 1;
        for (int i = 1; i <= cnt; ++i)
        {
            ans = ans * 2 % mod;
        }
        if (!dem) ans = (ans + mod - 1) % mod;
        cout << ans << '\n';
    }
    return 0;
}
