#include<string>
#include<fstream>
#include<unordered_set>
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>

#define ll long long

using namespace std;

long long const p = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int tt;
	cin >> tt;

	while (tt--) {
		int n, m;
		cin >> n >> m;

		bool fl = false;

		long long ans = 1;

		for(int i = 0; i < n; i++)
			for (int j = 0; j < m; j++) {
				char c;
				cin >> c;
				if (c == '0') {
					fl = true;
				}
				else {
					ans = (2ll * ans) % p;
				}
			}
		if (fl)
			cout << ans << '\n';
		else
			cout << ans - 1 << '\n';
	}

	return 0;
}