// Author: Lukas Polacek
// Date: September 28th, 2010
// Algorithm: Using stack
// Complexity: O(nm)

#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <stack>
#include <cstdio>
#include <cassert>
using namespace std;

#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)

typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int t; scanf("%d", &t);
    while (t--)
    {
        int n, m;
        scanf("%d %d", &n, &m);

        vi a[2] = {vi(m + 1, 0), vi(m + 1, 0)};
        char s[m + 1];
        vi stat(2 * (n + m) + 1, 0);
        rep(i,0,n)
        {
            scanf("%s", s);
            rep(j,0,m)
                if (s[j] == '#') a[i & 1][j + 1] = 0;
                else a[i & 1][j + 1] = a[!(i & 1)][j + 1] + 1;

            stack<pii> z;
            z.push(pii(0, -1234567));
            vi &b = a[i & 1];
            rep(j,1,m + 1)
            {
                while (b[z.top().first] > b[j]) z.pop();

                int res = 0;
                if (b[j] > 0)
                {
                    z.push(pii(j, max(b[j] - z.top().first, z.top().second)));
                    res = 2 * (z.top().second + j);
                }
                else
                    z.push(pii(j, -1234567));

                stat[res]++;
            }
        }

        rep(i,4,stat.size()) if (stat[i] > 0)
            printf("%d x %d\n", stat[i], i);
    }
}
