// the main idea is first fill whole plain X to one X and lastly count the number of X in each die
#include <iostream>
#include <vector>
using namespace std;

char c[60][60];
int X, Y;
vector<int> v;
int counter;
int c2 = 1;

void floodfill(int x, int y);

void print(){
	for (int i = 0; i < Y; i++){
		for (int j = 0; j < X; j++){
			cout << c[i][j];
		}
		cout << endl;
	}
	cout << endl;
}

void floodfillx(int x, int y){
	if (x < 0 || y < 0 || x >= X || y >= Y || c[y][x] == '.' || c[y][x] == '*')
		return;
	c[y][x] = '*';
	floodfillx(x-1, y);
	floodfillx(x+1, y);
	floodfillx(x, y+1);
	floodfillx(x, y-1);
}

void floodfill(int x, int y){
	if (x < 0 || y < 0 || x >= X || y >= Y || c[y][x] == '.')
		return;
	if (c[y][x] == 'X')
		counter++;
	c[y][x] = '.';
	floodfill(x-1, y);
	floodfill(x+1, y);
	floodfill(x, y+1);
	floodfill(x, y-1);
}

int main(){
	
	while (cin >> X >> Y, X | Y){
		v.clear();
		
		for (int i = 0; i < Y; i++)
			for (int j = 0; j < X; j++)
				cin >> c[i][j];
		
		for (int i = 0; i < Y; i++)
			for (int j = 0; j < X; j++)
				if (c[i][j] == 'X'){
					floodfillx(j, i);
					c[i][j] = 'X';
				}
		
		for (int i = 0; i < Y; i++){
			for (int j = 0; j < X; j++)
				if (c[i][j] == 'X'){
					counter = 0;
					floodfill(j, i);
					v.push_back(counter);
				}
		}
		
		sort(v.begin(), v.end());
		
		printf("Throw %d\n", c2++);
		for (int i = 0; i < v.size(); i++){
			if (i)
				printf(" ");
			cout << v[i];
		}
		printf("\n\n");
	}
	
	return 0;
}
