// You're not going to master the rest of your life in one day.
// Just relax. Master the day.
// Then just keep doing that every day.
#include<bits/stdc++.h>
using namespace std;

//=========================================================MACROS & CONSTS=========================================================\\

#define int             long long
#define ull             unsigned long long
#define lld             long double
#define endl            '\n'
#define pb              push_back
#define ff              first
#define ss              second
#define vi              vector<int>
#define pii             pair<int,int>
#define sz(x)           (int)((x).size())
#define ps(x,y)         fixed<<setprecision(y)<<x
#define setbits(x)      __builtin_popcountll(x)
#define all(x)          (x).begin(), (x).end()
#define fast()          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define REP(i, st, en)  for(__typeof(en) i = (st)-(st>en); i != (en)-(st>en); i += 1-2*(st>en)) // ford: [), back: (]

const double PI = 3.141592653589793238460;
const int mod = 1000000007;
const int INF = (int)1e18;

//=========================================================MACROS & CONSTS=========================================================\\

//=============================================================DEBUGGER=============================================================\\

void _print(int t) {cerr << t;}
void _print(unsigned t) {cerr << t;}
void _print(unsigned long t) {cerr << t;}
void _print(unsigned long long t) {cerr << t;}
void _print(float t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(long double t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(const char *t) {cerr << t;}
void _print(const string &t) {cerr << t;}
void _print(bool t) {cerr << (t ? "true" : "false");}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x);
#endif

//=============================================================DEBUGGER=============================================================\\

//=========================================================UTILITY FUNCTIONS=========================================================\\

bool comp(const pair<int, int> &a, const pair<int, int> &b){ return (a.first > b.second);}
int expo(int a, int n, int m){ int res = 1; while(n > 0){ if (n & 1) res = (res * a) % m; a = (a * a) % m; n = n >> 1;} return res;}
vector<int> sieve(int n) {int* arr = new int[n + 1](); vector<int> primes; for(int i = 2; i <= n; i++) if (arr[i] == 0){ primes.push_back(i); for(int j = 2 * i; j <= n; j += i) arr[j] = 1;} return primes;}
//=========================================================UTILITY FUNCTIONS=========================================================\\

// Speak Out Loud What You Are Thinking While Solving Problem
// Work Hard And Solve Problems Above Your Level

void solve(){
  int n, m;
  cin >> n >> m;

  int cnt = 0;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < m; j++){
      char c;
      cin >> c;
      if(c == '#')
        cnt++;
    }
  }

  cout << expo(2, cnt, mod) - (cnt == m * n) << endl;
}

int32_t main(){
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
  fast();
  int t = 1;
  cin >> t;
  while(t--){
    solve();
  }
  return 0;
}