????:??
??:
??a,b,c?,??????????d?

??d??ab?????,??c??d????

????d???????

??:

????1000,???????????a????????b??????

????ansL + lenc + ansR

ansL??ab???????????,ansR?????????????????

lenc????????????????

???????n^2?????????

???????????

//HDU 4681 O(n^2)

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1050;
int dp1[maxn][maxn], dp2[maxn][maxn];
int l1[maxn], l2[maxn], len1, len2, len3;
char s1[maxn], s2[maxn], s3[maxn];
void update(int &x, int y){x = max(x, y);}
void pre_deal(){
    for(int i = 1; i <= len1; i++){
        int l = 1;
        for(int j = i; j <= len1; j++){
            if(s1[j] == s3[l]) l++;
            if(l > len3){
                l1[i] = j;
                break;
            }
        }
    }
    for(int i = 1; i <= len2; i++){
        int l = 1;
        for(int j = i; j <= len2; j++){
            if(s2[j] == s3[l]) l++;
            if(l > len3){
                l2[i] = j;
                break;
            }
        }
    }
    for(int i  = 1; i <= len1; i++){
        for(int j = 1; j <= len2; j++){
            if(s1[i] == s2[j]){
                update(dp1[i][j], dp1[i-1][j-1]+1);
            }
            update(dp1[i][j], dp1[i-1][j]);
            update(dp1[i][j], dp1[i][j-1]);
        }
    }
    reverse(s1+1, s1+len1+1);
    reverse(s2+1, s2+len2+1);
    for(int i = 1; i <= len1; i++){
        for(int j = 1; j <= len2; j++){
            if(s1[i] == s2[j]){
                update(dp2[i][j], dp2[i-1][j-1]+1);
            }
            update(dp2[i][j], dp2[i-1][j]);
            update(dp2[i][j], dp2[i][j-1]);
        }
    }
}
int main(){
    int T, ks = 0;
    scanf("%d", &T);
    while(T--){
        memset(dp1, 0, sizeof(dp1));
        memset(dp2, 0, sizeof(dp2));
        memset(l1, -1, sizeof(l1));
        memset(l2, -1, sizeof(l2));
        scanf("%s", s1+1);
        scanf("%s", s2+1);
        scanf("%s", s3+1);
        len1 = strlen(s1+1);
        len2 = strlen(s2+1);
        len3 = strlen(s3+1);
        pre_deal();
        int ans = 0;
        for(int i = 1; i <= len1; i++){
            for(int j = 1; j <= len2; j++){
                if(l1[i] == -1 || l2[j] == -1) continue;
                update(ans, dp1[i-1][j-1]+len3+dp2[len1-l1[i]][len2-l2[j]]);
            }
        }
        printf("Case #%d: %d\n", ++ks, ans);
    }
    return 0;
}