//12252024832524
#include <cstdio>
#include <cstring>
#include <algorithm>
#define TT template<typename T>
using namespace std;

typedef long long LL;
const int MAXN = 2005;
const int MOD = 1e9 + 7;
int n,m;
char a[MAXN][MAXN];

LL Read()
{
	LL x = 0,f = 1;char c = getchar();
	while(c > '9' || c < '0'){if(c == '-')f = -1;c = getchar();}
	while(c >= '0' && c <= '9'){x = (x*10) + (c^48);c = getchar();}
	return x * f;
}
TT void Put1(T x)
{
	if(x > 9) Put1(x/10);
	putchar(x%10^48);
}
TT void Put(T x,char c = -1)
{
	if(x < 0) putchar('-'),x = -x;
	Put1(x); if(c >= 0) putchar(c);
}
TT T Max(T x,T y){return x > y ? x : y;}
TT T Min(T x,T y){return x < y ? x : y;}
TT T Abs(T x){return x < 0 ? -x : x;}

int qpow(int x,int y)
{
	int ret = 1;
	while(y){if(y & 1) ret = 1ll * ret * x % MOD;x = 1ll * x * x % MOD;y >>= 1;}
	return ret;
}

int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);

	for(int T = Read(); T ;-- T)
	{
		n = Read(); m = Read(); int ans = 0;
		for(int i = 1;i <= n;++ i) scanf("%s",a[i]+1);
		for(int i = 1;i <= n;++ i)
			for(int j = 1;j <= m;++ j)
				if(a[i][j] == '#') ans++;
		if(ans == 1) Put(2,'\n');
		else if(ans == n*m) Put(qpow(2,ans)-1,'\n');
		else Put(qpow(2,ans),'\n');
	}
	return 0;
}
/*
000
001
010
100
101
012
210

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
omkar orz orz orz
122
*/
