简单的爆搜
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define MAXN 15
using std::cin;
using std::cout;
using std::endl;
using std::map;
using std::string;
using std::vector;
using std::min;
using std::max;
const double PI = acos(-1.0);
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1}; //UDLR
int N;
bool check(int x, int y) {
if (x >= 0 && x < N && y >= 0 && y < N) {
return true;
}
return false;
}
vector<string> mat;
int main() {
//freopen("input.in", "r", stdin);
int t, now = 0;
cin >> t;
while (t --) {
cin >> N;
mat.clear();
for (int i = 0; i < N; ++ i) {
string s;
cin >> s;
mat.push_back(s);
}
for (int i = 0; i < N; ++ i) {
for (int j = 0; j < N; ++ j) {
for (char c = 'A'; c <= 'Z'; ++ c) {
bool flag = true;
if (mat[i][j] == '.') {
for (int k = 0; k < 4; ++ k) {
int nx = i + dx[k], ny = j + dy[k];
if (check(nx, ny))
if (mat[nx][ny] == c) flag = false;
if (!flag) break;
}
if (flag) {
//puts("ok");
mat[i][j] = c; break;
}
}
}
}
}
printf("Case %d:\n", ++ now);
for (int i = 0; i < N; ++ i) cout << mat[i] << endl;
}
}