// Arup Guha
// 7/20/2015
// Solution to 2010 UCF Fall Locals Problem: Dr. Orooji's Exam

import java.util.*;

public class exam {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process all cases.
		for (int loop=1; loop<=numCases; loop++) {

			// Read in input.
			int r = stdin.nextInt();
			int c = stdin.nextInt();

			// Just keep track of how many X's are in each column...
			int[] vals = new int[c];
			for (int i=0; i<r; i++) {
				String row = stdin.next();
				for (int j=0; j<c; j++)
					if (row.charAt(j) == 'X')
						vals[j]++;
			}

			// Get total number of students, and number in odd rows (0 based)
			int total = 0;
			for (int i=0; i<c; i++)
				total += vals[i];

			// This is the fewest number of columns we must place students in.
			int minCols = (total+r-1)/r;

			// dp[i][j] stores the maximum # of student seated upto column i, including it,
			// with exactly j columns used. dp[i][0] must be 0 since we're using 0 columns.
			int[][] dp = new int[c][c+1];
			for (int i=0; i<c; i++) Arrays.fill(dp[i], -1);
			for (int i=0; i<c; i++) dp[i][0] = 0;
			dp[0][1] = vals[0];

			// Loop through columns.
			for (int i=1; i<c; i++) {

				// Just use this column, nothing else.
				dp[i][1] = vals[i];

				// Fill in value for each number of used columns.
				for (int j=2; j<=c; j++) {

					// Avoid array out of bounds.
					int opt1 = i>=2 ? dp[i-2][j-1] : -1;
					int opt2 = i>=3 ? dp[i-3][j-1] : -1;
					if (opt1 == -1 && opt2 == -1) continue;

					// Just one option in these two cases.
					if (opt1 == -1)      dp[i][j] = vals[i] + dp[i-3][j-1];
					else if (opt2 == -1) dp[i][j] = vals[i] + dp[i-2][j-1];

					// Take the best option.
					else dp[i][j] = vals[i] + Math.max(dp[i-3][j-1], dp[i-2][j-1]);
				}
			}

			// Find the largest valid sum.
			int max = -1;
			for (int i=0; i<c; i++)
				for (int j=minCols; j<=c; j++)
					max = Math.max(max, dp[i][j]);

			// Output appropriately based on the max number we can put in the desired # of columns.
			if (max == -1)
				System.out.println("Seating arrangement #"+loop+": Can not be fixed.");
			else
				System.out.println("Seating arrangement #"+loop+": At least "+(total - max) +" student(s) need to be moved.");
			System.out.println();
		}
	}
}