// NWERC'10 solution for problem 'rectangle'
// Jaap Eldering

#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;

typedef vector<int> VI;
typedef vector<VI>  VVI;

typedef pair<int,int> PI;

const int infty = 999999999;

int main()
{
	int run, nruns;

	cin >> nruns;

	for(run=1; run<=nruns; run++) {
		int X, Y;
		cin >> Y >> X;

		vector<string> rect(Y);
		for(int y=0; y<Y; y++) cin >> rect[y];

		VVI maxh(Y,VI(X,0));
		for(int x=0; x<X; x++) if ( rect[0][x]=='.' ) maxh[0][x] = 1;

		for(int y=1; y<Y; y++) {
			for(int x=0; x<X; x++)
				if ( rect[y][x]=='.' ) 	maxh[y][x] = maxh[y-1][x] + 1;
		}

		vector<int> res(X+Y+1);

		for(int y=0; y<Y; y++) {
			stack< PI > st; // startx, height
			for(int x=0; x<X; x++) {
				int bestx = x;
				while ( !st.empty() && st.top().second>maxh[y][x] ) {
					if ( st.top().first < bestx ) bestx = st.top().first;
					st.pop();
				}
				if ( rect[y][x]=='#' ) continue;
				if ( st.empty() ||
				     x-bestx+1+maxh[y][x] > x-st.top().first+1 + st.top().second ) {
					st.push(PI(bestx,maxh[y][x]));
				}
				res[x-st.top().first+1 + st.top().second]++;
			}
		}

		for(int i=0; i<res.size(); i++)
			if ( res[i]>0 ) cout << res[i] << " x " << 2*i << endl;
	}

	return 0;
}
