#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while(t--){
char grid[3][3];
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
cin >> grid[i][j];
}
}
int f[3];
for(int i=0; i<3; i++) f[i] = 0;
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
if(grid[i][j] == '?'){
for(int k=0; k<3; k++){
int ind = grid[i][k] - 'A';
f[ind]++;
}
}
else
continue;
}
}
char ch;
for(int i=0; i<3; i++){
if(f[i] == 2){
ch = i + 65;
break;
}
}
cout << ch << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgdDsKCWNpbiA+PiB0OwoJd2hpbGUodC0tKXsKCQljaGFyIGdyaWRbM11bM107CgkJZm9yKGludCBpPTA7IGk8MzsgaSsrKXsKCQkJZm9yKGludCBqPTA7IGo8MzsgaisrKXsKCQkJCWNpbiA+PiBncmlkW2ldW2pdOwoJCQl9CgkJfQoJCWludCBmWzNdOwoJCWZvcihpbnQgaT0wOyBpPDM7IGkrKykgZltpXSA9IDA7CgkJZm9yKGludCBpPTA7IGk8MzsgaSsrKXsKCQkJZm9yKGludCBqPTA7IGo8MzsgaisrKXsKCQkJCWlmKGdyaWRbaV1bal0gPT0gJz8nKXsKCQkJCQlmb3IoaW50IGs9MDsgazwzOyBrKyspewoJCQkJCQlpbnQgaW5kID0gZ3JpZFtpXVtrXSAtICdBJzsKCQkJCQkJZltpbmRdKys7CgkJCQkJfQoJCQkJfQoJCQkJZWxzZQoJCQkJCWNvbnRpbnVlOwoJCQl9CgkJfQoJCWNoYXIgY2g7CgkJZm9yKGludCBpPTA7IGk8MzsgaSsrKXsKCQkJaWYoZltpXSA9PSAyKXsKCQkJCWNoID0gaSArIDY1OwoJCQkJYnJlYWs7CgkJCX0KCQl9CgkJCgkJY291dCA8PCBjaCA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=