#include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define modulo ll (1e9 + 7)
#define EPS 1e-9
typedef long long ll;
typedef pair<int,int> pii;
void init(){
cin.tie(0);
cin.sync_with_stdio(0);
}
const int N = 509, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;
int n, m, knight[N];
bool emptyCell[N][N];
//first index is a dummy state
int dx[] = {-1000, 2, 2, 1, 1, -1, -1, -2,-2};
int dy[] = {-1000, 1,-1, 2,-2, 2, -2, 1, -1};
inline bool valid(int i, int j){
return (i >= 0 && i < n && j >= 0 && j < m);
}
inline bool valid2(int i, int m, int &newR, int &newC){
if(i < 0 || m == 0) return 1;
int r = i + dx[m];
int c = knight[i] + dy[m];
return !(r == newR && c == newC);
}
int dp[N][3][5][5][7], vis[N][3][5][5][7], vid;
//Top-down approach
int solve(int i, int first, int second, int third, int fourth){
if(i == n) return 1;
int &ret = dp[i][first][second][third][fourth];
if(vis[i][first][second][third][fourth] == vid) return ret;
vis[i][first][second][third][fourth] = vid;
ret = 0;
for(int k = 1;k < 9;k++){
int r = i + dx[k];
int c = knight[i] + dy[k];
if(valid(r, c) && emptyCell[r][c] && valid2(i - 4, first, r, c) && valid2(i - 3, second, r, c) && valid2(i - 2, third, r, c) && valid2(i - 1, fourth, r, c)){
ret += solve(i + 1, (second > 2 ? 0 : second), third, (fourth > 4 ? 0 : fourth), (k > 6 ? 0 : k));
while(ret >= modulo) ret -= modulo;
}
}
return ret;
}
//Bottom-up approach
int solve(){
for(int first = 2;first >= 0;first--)
for(int second = 4;second >= 0;second--)
for(int third = 4;third >= 0;third--)
for(int fourth = 6;fourth >= 0;fourth--)
dp[n][first][second][third][fourth] = 1;
for(int i = n - 1;i >= 0;i--){
for(int k = 1;k < 9;k++){
int r = i + dx[k];
int c = knight[i] + dy[k];
if(!(valid(r, c) && emptyCell[r][c])) continue;
for(int first = 2;first >= 0;first--){
for(int second = 4;second >= 0;second--){
for(int third = 4;third >= 0;third--){
for(int fourth = 6;fourth >= 0;fourth--){
if(valid2(i - 4, first, r, c) && valid2(i - 3, second, r, c) && valid2(i - 2, third, r, c) && valid2(i - 1, fourth, r, c)){
int &ret = dp[i][first][second][third][fourth];
if(vis[i][first][second][third][fourth] != vid){
vis[i][first][second][third][fourth] = vid;
ret = 0;
}
ret += dp[i + 1][(second > 2 ? 0 : second)][third][(fourth > 4 ? 0 : fourth)][(k > 6 ? 0 : k)];
while(ret >= modulo) ret -= modulo;
}
}
}
}
}
}
}
return dp[0][0][0][0][0];
}
inline void go(int tc = 0){
scanf("%d%d", &n, &m);
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
emptyCell[i][j] = 1;
char c;
scanf(" %c", &c);
if(c != '.'){
emptyCell[i][j] = 0;
if(c == '*') knight[i] = j;
}
}
}
vid++;
printf("%d\n", solve());
}
int main(){
// freopen("knights.in", "r", stdin);
int t;
scanf("%d", &t);
while(t--)
go();
}
I2luY2x1ZGUgImJpdHMvc3RkYysrLmgiCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBGIGZpcnN0CiNkZWZpbmUgUyBzZWNvbmQKI2RlZmluZSBtb2R1bG8gbGwgKDFlOSArIDcpCiNkZWZpbmUgRVBTIDFlLTkKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LGludD4gcGlpOwoKdm9pZCBpbml0KCl7CiAgICBjaW4udGllKDApOwogICAgY2luLnN5bmNfd2l0aF9zdGRpbygwKTsKfQoKY29uc3QgaW50IE4gPSA1MDksIE0gPSAxZTYgKyA5LCBPTyA9IDB4M2YzZjNmM2Y7CmNvbnN0IGxsIGxsT08gPSAweDNmM2YzZjNmM2YzZjNmM2Y7CgppbnQgbiwgbSwga25pZ2h0W05dOwoKYm9vbCBlbXB0eUNlbGxbTl1bTl07CgovL2ZpcnN0IGluZGV4IGlzIGEgZHVtbXkgc3RhdGUKaW50IGR4W10gPSB7LTEwMDAsIDIs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gZmlyc3QsIHIsIGMpICYmIHZhbGlkMihpIC0gMywgc2Vjb25kLCByLCBjKSAmJiB2YWxpZDIoaSAtIDIsIHRoaXJkLCByLCBjKSAmJiB2YWxpZDIoaSAtIDEsIGZvdXJ0aCwgciwgYykpewogICAgICAgICAgICByZXQgKz0gc29sdmUoaSArIDEsIChzZWNvbmQgPiAyID8gMCA6IHNlY29uZCksIHRoaXJkLCAoZm91cnRoID4gNCA/IDAgOiBmb3VydGgpLCAoayA+IDYgPyAwIDogaykpOwogICAgICAgICAgICB3aGlsZShyZXQgPj0gbW9kdWxvKSAgICByZXQgLT0gbW9kdWxvOwogICAgICAgIH0KICAgIH0KCiAgICByZXR1cm4gcmV0Owp9CgoKLy9Cb3R0b20tdXAgYXBwcm9hY2gKCmludCBzb2x2ZSgpewoKICAgIGZvcihpbnQgZmlyc3QgPSAyO2ZpcnN0ID49IDA7Zmlyc3QtLSkKICAgICAgICBmb3IoaW50IHNlY29uZCA9IDQ7c2Vjb25kID49IDA7c2Vjb25kLS0pCiAgICAgICAgICAgIGZvcihpbnQgdGhpcmQgPSA0O3RoaXJkID49IDA7dGhpcmQtLSkKICAgICAgICAgICAgICAgIGZvcihpbnQgZm91cnRoID0gNjtmb3VydGggPj0gMDtmb3VydGgtLSkKICAgICAgICAgICAgICAgICAgICBkcFtuXVtmaXJzdF1bc2Vjb25kXVt0aGlyZF1bZm91cnRoXSA9IDE7CgoKICAgIGZvcihpbnQgaSA9IG4gLSAxO2kgPj0gMDtpLS0pewogICAgICAgIGZvcihpbnQgayA9IDE7ayA8IDk7aysrKXsKICAgICAgICAgICAgaW50IHIgPSBpICsgZHhba107CiAgICAgICAgICAgIGludCBjID0ga25pZ2h0W2ldICsgZHlba107CiAgICAgICAgICAgIGlmKCEodmFsaWQociwgYykgJiYgZW1wdHlDZWxsW3JdW2NdKSkgICBjb250aW51ZTsKCiAgICAgICAgICAgIGZvcihpbnQgZmlyc3QgPSAyO2ZpcnN0ID49IDA7Zmlyc3QtLSl7CiAgICAgICAgICAgICAgICBmb3IoaW50IHNlY29uZCA9IDQ7c2Vjb25kID49IDA7c2Vjb25kLS0pewogICAgICAgICAgICAgICAgICAgIGZvcihpbnQgdGhpcmQgPSA0O3RoaXJkID49IDA7dGhpcmQtLSl7CiAgICAgICAgICAgICAgICAgICAgICAgIGZvcihpbnQgZm91cnRoID0gNjtmb3VydGggPj0gMDtmb3VydGgtLSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZih2YWxpZDIoaSAtIDQsIGZpcnN0LCByLCBjKSAmJiB2YWxpZDIoaSAtIDMsIHNlY29uZCwgciwgYykgJiYgdmFsaWQyKGkgLSAyLCB0aGlyZCwgciwgYykgJiYgdmFsaWQyKGkgLSAxLCBmb3VydGgsIHIsIGMpKXsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgJnJldCA9IGRwW2ldW2ZpcnN0XVtzZWNvbmRdW3RoaXJkXVtmb3VydGhdOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmKHZpc1tpXVtmaXJzdF1bc2Vjb25kXVt0aGlyZF1bZm91cnRoXSAhPSB2aWQpewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2aXNbaV1bZmlyc3RdW3NlY29uZF1bdGhpcmRdW2ZvdXJ0aF0gPSB2aWQ7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldCA9IDA7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHJldCArPSBkcFtpICsgMV1bKHNlY29uZCA+IDIgPyAwIDogc2Vjb25kKV1bdGhpcmRdWyhmb3VydGggPiA0ID8gMCA6IGZvdXJ0aCldWyhrID4gNiA/IDAgOiBrKV07CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgd2hpbGUocmV0ID49IG1vZHVsbykgICAgcmV0IC09IG1vZHVsbzsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiBkcFswXVswXVswXVswXVswXTsKfQoKCgppbmxpbmUgdm9pZCBnbyhpbnQgdGMgPSAwKXsKICAgIHNjYW5mKCIlZCVkIiwgJm4sICZtKTsKICAgIAogICAgZm9yKGludCBpID0gMDtpIDwgbjtpKyspewogICAgICAgIGZvcihpbnQgaiA9IDA7aiA8IG07aisrKXsKICAgICAgICAgICAgZW1wdHlDZWxsW2ldW2pdID0gMTsKICAgICAgICAgICAgY2hhciBjOwogICAgICAgICAgICBzY2FuZigiICVjIiwgJmMpOwogICAgICAgICAgICBpZihjICE9ICcuJyl7CiAgICAgICAgICAgICAgICBlbXB0eUNlbGxbaV1bal0gPSAwOwogICAgICAgICAgICAgICAgaWYoYyA9PSAnKicpICAgIGtuaWdodFtpXSA9IGo7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CgogICAgdmlkKys7CgogICAgcHJpbnRmKCIlZFxuIiwgc29sdmUoKSk7Cn0KCgppbnQgbWFpbigpewoKLy8gICAgZnJlb3Blbigia25pZ2h0cy5pbiIsICJyIiwgc3RkaW4pOwoKICAgaW50IHQ7CiAgICBzY2FuZigiJWQiLCAmdCk7CiAgICB3aGlsZSh0LS0pCiAgICAgICAgZ28oKTsKfQ==