//
// Created by bezaliel on 09/06/21.
//

#include <bits/stdc++.h>
using namespace std;

long long MOD = 1000000007;

long long bin_pow(int k) {
    if (k == 0)
        return 1;
    if (k % 2 == 0) {
        long long x = bin_pow(k / 2);
        return (x * x) % MOD;
    } else {
        return (2 * bin_pow(k - 1)) % MOD;
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    long long counter = 0;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;

        for (int j = 0; j < m; ++j) {
            counter += s[j] == '#' ? 1:0;
        }
    }

    long long int result = bin_pow(counter);
    result -= counter == n * m ? 1 : 0;
    cout << result << endl;
}

int main() {

//    freopen("../input.txt", "r", stdin);
//    freopen("../output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}