#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <long long, long long>;

void boost ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int n, m, k, wyn, mod=1000000007;
string s;

void solve ()
{
    k = 0;
    cin >> n >> m;
    for (int i=0; i<n; i++)
    {
        cin >> s;
        for (int j=0; j<m; j++)
            if (s[j] == '#')
                k++;
    }
    wyn = 1;
    for (int i=1; i<=k; i++)
        wyn = (wyn * 2) % mod;
    if (k == n*m)
        wyn--;
    cout << wyn << "\n";
}

int main ()
{
    boost();
    int t = 1;
    cin >> t;
    //scanf ("%d", &t);
    while (t--)
        solve();

    return 0;
}

