// Arup Guha
// 4/23/2013
// Solution to 2013 UCF High School Contest Problem: Find X.

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

public class find {
	
	public static void main(String[] args) throws Exception {
		
		Scanner fin = new Scanner(new File("find.in"));		
		int numCases = fin.nextInt();

		// Go through all of the cases.
		for (int loop=1; loop<=numCases; loop++) {
			
			int numR = fin.nextInt();
			int numC = fin.nextInt();
			
			// Get the grid.
			char[][] grid = new char[numR][];
			for (int i=0; i<numR; i++) {
				String s = fin.next();
				grid[i] = s.toCharArray();
			}
			
			// Try each location as the middle and get the best.
			int ans = 0;
			for (int i=0; i<numR; i++) {
				for (int j=0; j<numC; j++) {
					int cur = getMax(grid, i,j);
					if (cur > ans)
						ans = cur;
				}
			}
			
			// Print the result.
			System.out.println("Page #"+loop+": "+ans);
		}
	}
	
	// Returns the size of the largest X centered at (x,y).
	public static int getMax(char[][] grid, int x, int y) {
		
		// Can't be the center.
		if (grid[x][y] != 'X') return 0;
		
		int d = 1;
		
		// We will iteratively grow our X.
		while (true) {
			boolean flag = true;
			
			// Try going further only if we're inbounds.
			if (inbounds(grid, x, y, d)) {
				
				// Easy way to loop through all four next positions.
				for (int dx=-1; dx<=1; dx+=2)
					for (int dy=-1; dy<=1; dy+=2)
						if (grid[x+dx*d][y+dy*d] != 'X')
							flag = false;
			}
			else 
				break;
			
			// If we're good, add 1 to our size.
			if (flag) 
				d++;
			else 
				break;
		}
		
		// Make the proper adjustment and return the answer.
		d--;
		return 2*d+1;
	}
	
	// See if all spots distance d away from (x,y) are in the grid.
	public static boolean inbounds(char[][] grid, int x, int y, int d) {
		int numR = grid.length;
		int numC = grid[0].length;
		
		if (x+d >= numR || x-d < 0) return false;
		if (y+d >= numC || y-d < 0) return false;
		return true;
	}
}

