#include <bits/stdc++.h>
using namespace std;
const int nextstep[4][2] = {{-1, -1}, {1, -1}, {-1, 1}, {1, 1}};
const int nextstep2[4][2] = {{-2, -2}, {2, -2}, {-2, 2}, {2, 2}};
int n;
char a[11][11];
int dfs(int x, int y, int step){
int maxn = -1;
for (int k = 0; k < 4; k++){
if (x + nextstep2[k][0] < 1 || x + nextstep2[k][0] > 10 || y + nextstep2[k][1] < 1 || y + nextstep2[k][1] > 10){
continue;
}
if (a[x + nextstep[k][0]][y + nextstep[k][1]] == 'B' && a[x + nextstep2[k][0]][y + nextstep2[k][1]] == '#'){
a[x + nextstep[k][0]][y + nextstep[k][1]] = '#';
maxn = max(maxn, dfs(x + nextstep2[k][0], y + nextstep2[k][1], step + 1));
a[x + nextstep[k][0]][y + nextstep[k][1]] = 'B';
}
}
if (maxn == -1){
return step;
} else {
return maxn;
}
}
int main(){
scanf("%d", &n);
while (n--){
bool flag = true;
for (int i = 1; i <= 10; i++){
scanf(" ");
for (int j = 1; j <= 10; j++){
scanf("%c", &a[i][j]);
}
}
for (int i = 1; i <= 10; i++){
for (int j = 1; j <= 10; j++){
if (a[i][j] == 'W'){
a[i][j] = '#';
printf("%d\n", dfs(i, j, 0));
flag = false;
}
}
}
if (flag) printf("0\n");
}
return 0;
}
WA on #1 第十行