#include #include #include using namespace std; const int INF = 1000000000; const int LIM = 2000005; int R, C, K; string G[LIM]; int solve() { cin >> R >> C >> K; for (int i = 1; i <= R; i++) { cin >> G[i]; } vector nb(LIM); for (int j = 0; j < C; j++) { int tot = 0; for (int i = 1; i <= R; i++) { tot += G[i][j] == 'X'; } int curr = 0; for (int i = 0; i <= R + 1; i++) { bool isX = 1 <= i && i <= R && G[i][j] == 'X'; curr += isX; if (isX || curr > K - 1 || tot - curr > R - K) { nb[i]++; } } } int ans = INF; for (int i = 0; i <= R + 1; i++) { ans = min(ans, abs(i - K) + nb[i]); } return ans; } int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { cout << "Case #" << t << ": " << solve() << endl; } return 0; }