/*input
4
3 4
0000
00#0
0000
2 1
#
#
1 2
##
6 29
#############################
#000##0###0##0#0####0####000#
#0#0##00#00##00####0#0###0#0#
#0#0##0#0#0##00###00000##00##
#000##0###0##0#0##0###0##0#0#
#############################
*/
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
    	int n, m;
    	cin >> n >> m;
    	bool chk = true;
    	ll ans = 1;
    	for (int i = 0; i < n; i++) {
    		string s;
    		cin >> s;
    		for (char c : s) {
    			if (c == '#') {
    				ans = ans * 2 % mod;
    			} else {
    				chk = false;
    			}
    		}
    	}

    	if (chk) {
    		ans = (ans - 1 + mod) % mod;
    	}

    	cout << ans << "\n";
    }
    return 0;
}