// Author: Adrian Kuegel

import java.io.*;
import java.util.*;

public class adrian {
	public static void main(String [] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int tc = Integer.parseInt(in.readLine());
		while (tc-- > 0) {
			StringTokenizer strtok = new StringTokenizer(in.readLine());
			int n = Integer.parseInt(strtok.nextToken());
			int m = Integer.parseInt(strtok.nextToken());
			String [] grid = new String[n];
			for (int i=0; i<n; ++i)
				grid[i] = in.readLine();
			int [] height = new int[m+1];
			int [] cnt = new int[(n+m)*2+1];
			int [] res = new int[m+1];
			int [] lb = new int[m+1];
			for (int i=0; i<n; ++i) {
				int l = 1;
				lb[0] = 0;
				for (int j=0; j<m; )
					if (grid[i].charAt(j++) == '#') {
						height[j] = 0;
						l = 1;
						lb[0] = j;
						res[j] = 0;
					}
					else {
						int best = 0;
						++height[j];
						while(height[j] < height[lb[l-1]]) {
							--l;
							best = Math.max(best, j-lb[l]+1+height[j]);
						}
						res[j] = Math.max(res[lb[l-1]], height[j])+j-lb[l-1];
						lb[l++] = j;
						best = Math.max(best, res[j]);
						++cnt[best*2];
					}
			}
			for (int i=1; i<=(n+m)*2; ++i)
				if (cnt[i] > 0)
					System.out.println(cnt[i] + " x " + i);
		}
	}
}
