/*
	[NWERC'10] RECTANGLES
	By: Jan Kuipers
*/

#include <iostream>
#include <vector>

using namespace std;

int main () {

	int runs;
	cin>>runs;

	while (runs--) {

		int X,Y;
		cin>>Y>>X;

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

		vector<vector<int> > dy(Y, vector<int>(X, 0));

		for (int y=0; y<Y; y++)
			for (int x=0; x<X; x++)
				if (s[y][x]=='.') dy[y][x] = (y==0 ? 1 : dy[y-1][x]+1);

		vector<int> cnt(2*(Y+X)+1,0);
		
		for (int y=0; y<Y; y++) {
			vector<int> ex,h;

			for (int x=0; x<X; x++) {
				if (s[y][x]=='#') {
					ex.clear();
					h.clear();
					continue;
				}
				
				int nex=x;
				while (!h.empty() && h.back()>dy[y][x]) {
					nex=ex.back();
					ex.pop_back();
					h.pop_back();
				}

				if (h.empty() || -nex+dy[y][x] > -ex.back()+h.back()) {
					ex.push_back(nex);
					h.push_back(dy[y][x]);
				}

				cnt[2*(x-ex.back()+1+h.back())]++;
			}
		}

		for (int i=0; i<cnt.size(); i++)
			if (cnt[i]!=0) cout << cnt[i] << " x " << i << endl;
	}
	
	return 0;
}
