///////////
// // //
// ////////////////////
// // //
//
///////////
//
//
// // // //////// /\ /////////
// // // // // // //
// //////// // // // // //
// // // // // // //
////////// //////// // // // /////////////
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <list>
#include <stack>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <random>
#include <numeric>
#include <functional>
//#include <Windows.h>
using namespace std;
#define fa(i,op,n) for (int i = op; i <= n; i++)
#define fb(j,op,n) for (int j = op; j >= n; j--)
#define pb push_back
#define HashMap unordered_map
#define HashSet unordered_set
#define var auto
#define all(i) i.begin(), i.end()
#define all1(i) i.begin() + 1,i.end()
#define endl '\n'
#define px first
#define py second
#define DEBUG(a) cout<<a<<endl
using VI = vector<int>;
using VL = vector<long long>;
using ll = long long;
using ull = unsigned long long;
using db = double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T1, class T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& ve) {
for (T i : ve)
out << i << ' ';
return out;
}
template<class T1, class T2>
ostream& operator<<(ostream& out, const map<T1, T2>& mp) {
for (auto i : mp)
out << i << '\n';
return out;
}
const int INF = 0x3f3f3f3f;
const ll LNF = 0x3f3f3f3f3f3f3f3f;
const int IINF = 0x7fffffff;
const int iinf = 0x80000000;
const ll LINF = 0x7FFFFFFFFFFFFFFF;
const ll linf = 0x8000000000000000;
int dx[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[8] = { 0, 0, 1, -1, 1, -1, -1, 1 };
#include "Lynia.h"
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
void solve(int CASE)
{
int r, c; cin >> r >> c;
var a = vector<string>(r + 1);
fa(i, 1, r)cin >> a[i], a[i] = ' ' + a[i];
// 扩展域并查集
var s = vector<int>(2 * r + 1);
fa(i, 1, 2 * r)s[i] = i;
// 每列出现 1 的各个行
var g = vector<vector<int>>(c + 1);
fa(i, 1, r)
fa(j, 1, c)
if (a[i][j] == '1')
g[j].pb(i);
var find = [&](var find, int x)->int {
if (x != s[x])return s[x] = find(find, s[x]);
return s[x];
};
var merge = [&](int x, int y)->void {
s[find(find, y)] = find(find, x);
};
if (c % 2 == 1 and g[(c + 1) / 2].size() > 1) {
cout << 0 << endl;
return;
}
fa(i, 1, c / 2) { // 枚举列
var j = c - i + 1;
var tot = g[i].size() + g[j].size();
if (tot > 2) {
cout << 0 << endl;
return;
}
if (tot <= 1)continue;
if (g[i].size() == 2) {
merge(g[i][0], g[i][1] + r);
merge(g[i][1], g[i][0] + r);
}
else if (g[j].size() == 2) {
merge(g[j][0], g[j][1] + r);
merge(g[j][1], g[j][0] + r);
}
else {
merge(g[i][0], g[j][0]);
merge(g[i][0] + r, g[j][0] + r);
}
}
int ans = 0;
fa(i, 1, 2 * r)ans += (s[i] == i);
cout << Math::fastPow(2, ans / 2, mod) << endl;
return;
}
int main()
{
//SetConsoleOutputCP(CP_UTF8);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int _ = 1;
cin >> _;
fa(i, 1, _)solve(i);
return 0;
}