package com.yongk.algospot.BOARDCOVER;

import java.util.Scanner;

public class BOARDCOVER {
	static final int vector[][][] = {
			  { { 0, 0 }, { 1, 0 }, { 0, 1 } },
			  { { 0, 0 }, { 0, 1 }, { 1, 1 } },
			  { { 0, 0 }, { 1, 0 }, { 1, 1 } },
			  { { 0, 0 }, { 1, 0 }, { 1, -1 } },
	};
	static int board[][] = null;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.nextLine().trim());
		while(N-- > 0) {
			String[] XY = sc.nextLine().split(" ");
			int y = Integer.parseInt(XY[0]);
			int x = Integer.parseInt(XY[1]);
			board = new int[y][x];
			for (int i = 0; i < y; i++) {
				char[] matrix_temp = sc.nextLine().trim().toCharArray();
				for (int j = 0; j < x; j++) {
					if (matrix_temp[j] == '#') {
						board[i][j] = 1;
					} else {
						board[i][j] = 0;
					}
				}
			}
			System.out.println(cover());
			board = null;
		}
			
	}
	
	private static int cover() {
		int x = -1;
		int y = -1;
		for (int i = 0; i < board.length; i++) {
			for (int j = 0; j < board[0].length; j++) {
				if (board[i][j] == 0) {
					y = i;
					x = j;
					break;
				}
			}
			if (y != -1)
				break;
		}
		// base case
		if (y == -1)
			return 1;
		
		int ret = 0;
		for (int i = 0; i < 4; i++) {
			if (set(board, y, x, i, 1)) {
				ret += cover();
				
			}
			set(board, y, x, i, -1);
		}
		
		return ret;
	}

	private static boolean set(int[][] board, int y, int x, int type, int flag) {
		boolean ok = true;
		for (int i = 0; i < 3; i++) {
			int ny = y + vector[type][i][0];
			int nx = x + vector[type][i][1];
			if (ny < 0 || ny >= board.length || nx < 0 || nx >= board[0].length) {
				ok = false;
				continue;
			}
			board[ny][nx] += flag;
			if (board[ny][nx] > 1)
				ok = false;
		}
		return ok;
	}
}
