//-----------------CODED BY ROCKHOPPER130-----------------
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#define MOD 1000000007
// #define int long long
#define nish signed
using namespace std;
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int T = 0;
//--------------------------DEBUG-------------------------
void __print(int32_t x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '"' << x << '"'; }
void __print(const string &x) { cerr << '"' << x << '"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename A>
void __print(const A &x);
template <typename A, typename B>
void __print(const pair<A, B> &p);
template <typename... A>
void __print(const tuple<A...> &t);
template <typename T>
void __print(stack<T> s);
template <typename T>
void __print(queue<T> q);
template <typename T, typename... U>
void __print(priority_queue<T, U...> q);
template <typename A>
void __print(const A &x) {
bool first = true;
cerr << '{';
for (const auto &i : x) {
cerr << (first ? "" : ","), __print(i);
first = false;
}
cerr << '}';
}
template <typename A, typename B>
void __print(const pair<A, B> &p) {
cerr << '(';
__print(p.first);
cerr << ',';
__print(p.second);
cerr << ')';
}
template <typename... A>
void __print(const tuple<A...> &t) {
bool first = true;
cerr << '(';
apply([&first](const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
cerr << ')';
}
template <typename T>
void __print(stack<T> s) {
vector<T> debugVector;
while (!s.empty()) {
T t = s.top();
debugVector.push_back(t);
s.pop();
}
reverse(debugVector.begin(), debugVector.end());
__print(debugVector);
}
template <typename T>
void __print(queue<T> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.front();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
template <typename T, typename... U>
void __print(priority_queue<T, U...> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.top();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail>
void _print(const Head &H, const Tail &...T) {
__print(H);
if (sizeof...(T))
cerr << ", ";
_print(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "Line:" << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif
//-----------------------PRE FUNCTIONS----------------------
int gcdExtended(int a, int b, int* x, int* y) {
// Base Case
if (a == 0) {
*x = 0, *y = 1;
return b;
}
// To store results of recursive call
int x1, y1;
int gcd = gcdExtended(b % a, a, &x1, &y1);
// Update x and y using results of recursive call
*x = y1 - (b / a) * x1;
*y = x1;
return gcd;
}
int modInverse(int A) {
int x, y;
int g = gcdExtended(A, MOD, &x, &y);
if (g != 1)
cout << "Inverse doesn't exist";
else
return (x % MOD + MOD) % MOD;
}
int ncr(int n, int r) {
int sum = 1;
for(int i = 1; i <= r; i++){
sum = (sum * (n - r + i) % MOD) * modInverse(i);
sum %= MOD;
}
return sum;
}
int qpow(int x,int y) {
int ans = 1;
while(y) {
if(y & 1) ans = ans * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return ans;
}
//----------------------------...----------------------------
int winner(vector<string> &curr, char target) {
// checkRow
int flag1 = 0;
for(int i = 0; i < 6; i++) {
for(int j = 0; j < 4; j++) {
int temp = 1;
for(int k = j; k < j + 4; k++) {
if(curr[i][k] != target) temp = 0;
}
if(temp) flag1 = 1;
}
}
// checkCol
int flag2 = 0;
for(int i = 0; i < 7; i++) {
for(int j = 0; j < 3; j++) {
int temp = 1;
for(int k = j; k < j + 4; k++) {
if(curr[k][i] != target) temp = 0;
}
if(temp) flag2 = 1;
}
}
// checkDiag
int flag3 = 0;
for(int i = 0; i < 6; i++) {
for(int j = 0; j < 7; j++) {
int temp = 1;
for(int k = 0; k < 4; k++) {
int ni = i + k;
int nj = j + k;
if(ni >= 0 && ni < 6 && nj >= 0 && nj < 7)
if(curr[ni][nj] != target) temp = 0;
else temp = 0;
}
if(temp) flag3 = 1;
temp = 1;
for(int k = 0; k < 4; k++) {
int ni = i - k;
int nj = j + k;
if(ni >= 0 && ni < 6 && nj >= 0 && nj < 7)
if(curr[ni][nj] != target) temp = 0;
else temp = 0;
}
if(temp) flag3 = 1;
temp = 1;
for(int k = 0; k < 4; k++) {
int ni = i + k;
int nj = j - k;
if(ni >= 0 && ni < 6 && nj >= 0 && nj < 7)
if(curr[ni][nj] != target) temp = 0;
else temp = 0;
}
if(temp) flag3 = 1;
temp = 1;
for(int k = 0; k < 4; k++) {
int ni = i - k;
int nj = j - k;
if(ni >= 0 && ni < 6 && nj >= 0 && nj < 7)
if(curr[ni][nj] != target) temp = 0;
else temp = 0;
}
if(temp) flag3 = 1;
}
}
if(flag1 || flag2 || flag3) return 1;
return 0;
}
// curr : 0 -> 'C', 1 -> 'F'
int dfs(int turn, int num, vector<string> &curr, vector<string> &v, vector<int> &h) {
if(num == 43) return 0;
int k = winner(curr, 'C') + 2 * winner(curr, 'F'); // 0 : No one, 1 : C, 2 : F
if(k != 0) return k;
array<int,2> otpt;
for(int i = 0; i < 7; i++) {
if(h[i] < 6) {
char toFind = ((turn % 2) ? 'F' : 'C');
if(v[h[i]][i] != toFind) continue;
curr[h[i]][i] = toFind;
h[i]++;
int temp = dfs(turn ^ 1, num + 1, curr, v, h);
curr[h[i]][i] = '.';
h[i]--;
if(temp == 1) otpt[0] = 1;
else if(temp == 2) otpt[1] = 1;
else if(temp == 3) otpt[0] = 1, otpt[1] = 1;
}
}
return otpt[0] + 2 * otpt[1];
}
void solve(){
T++;
vector<string> v(6);
for(int i = 0; i < 6; i++) cin >> v[i];
vector<string> curr(6, string(7,'.'));
vector<int> h(7, 0);
int otpt = dfs(0, 1, curr, v, h);
if(otpt == 3) cout << "?\n";
else if(otpt == 2) cout << "F\n";
else if(otpt == 1) cout << "C\n";
else if(otpt == 0) cout << "0\n";
}
nish main() {
ios::sync_with_stdio(0);
cin.tie(0);
int test = 1;
cin >> test;
int test_tot = test;
while(test--){
cout << "Case #" << test_tot - test << ": ";
solve();
}
return 0;
}