/// Accepted
#include<bits/stdc++.h>
using namespace std;
#define mx 102
int dp[mx][mx][mx];
char a[mx],b[mx],c[mx];
int lena, lenb, lenc;
int fun(int ida, int idb, int idc)
{
if(ida>=lena || idb>=lenb){
if(idc>=lenc)
return 0;
else return -500;
}
if(dp[ida][idb][idc]!=-1) return dp[ida][idb][idc];
int ret = 0;
if(idc==0){
if(a[ida]==b[idb]){
if(a[ida]==c[idc]){
ret = 1 + fun(ida+1, idb+1, idc+1);
ret = max(ret, 1 + fun(ida+1, idb+1, idc));
}
else{
ret = 1 + fun(ida+1, idb+1, idc);
}
}
else{
ret = fun(ida+1, idb, idc);
ret = max(ret, fun(ida, idb+1, idc));
}
}
else if(idc==lenc){
if(a[ida]==b[idb]){
ret = 1 + fun(ida+1, idb+1, idc);
}
else{
ret = fun(ida+1, idb, idc);
ret = max(ret, fun(ida, idb+1, idc));
}
}
else{
if(a[ida]==b[idb]){
if(a[ida]==c[idc]){
ret = 1 + fun(ida+1, idb+1, idc+1);
}
else{
ret = fun(ida+1, idb+1, idc);
}
}
else{
ret = fun(ida+1, idb, idc);
ret = max(ret, fun(ida, idb+1, idc));
}
}
return dp[ida][idb][idc] = ret;
}
int main()
{
int tc;
scanf("%d",&tc);
for(int t=1; t<=tc; t++){
scanf("%s%s%s",a,b,c);
lena = strlen(a);
lenb = strlen(b);
lenc = strlen(c);
memset(dp,-1,sizeof dp);
printf("Case %d: %d\n",t,max(0,fun(0,0,0)));
}
return 0;
}
Ly8vIEFjY2VwdGVkCiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbXggMTAyCmludCBkcFtteF1bbXhdW214XTsKY2hhciBhW214XSxiW214XSxjW214XTsKaW50IGxlbmEsIGxlbmIsIGxlbmM7CmludCBmdW4oaW50IGlkYSwgaW50IGlkYiwgaW50IGlkYykKewogICAgaWYoaWRhPj1sZW5hIHx8IGlkYj49bGVuYil7CiAgICAgICAgaWYoaWRjPj1sZW5jKQogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBlbHNlIHJldHVybiAtNTAwOwogICAgfQogICAgaWYoZHBbaWRhXVtpZGJdW2lkY10hPS0xKSByZXR1cm4gZHBbaWRhXVtpZGJdW2lkY107CiAgICBpbnQgcmV0ID0gMDsKICAgIGlmKGlkYz09MCl7CiAgICAgICAgaWYoYVtpZGFdPT1iW2lkYl0pewogICAgICAgICAgICBpZihhW2lkYV09PWNbaWRjXSl7CiAgICAgICAgICAgICAgICByZXQgPSAxICsgZnVuKGlkYSsxLCBpZGIrMSwgaWRjKzEpOwogICAgICAgICAgICAgICAgcmV0ID0gbWF4KHJldCwgMSArIGZ1bihpZGErMSwgaWRiKzEsIGlkYykpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICByZXQgPSAxICsgZnVuKGlkYSsxLCBpZGIrMSwgaWRjKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICByZXQgPSBmdW4oaWRhKzEsIGlkYiwgaWRjKTsKICAgICAgICAgICAgcmV0ID0gbWF4KHJldCwgZnVuKGlkYSwgaWRiKzEsIGlkYykpOwogICAgICAgIH0KICAgIH0KICAgIGVsc2UgaWYoaWRjPT1sZW5jKXsKICAgICAgICBpZihhW2lkYV09PWJbaWRiXSl7CiAgICAgICAgICAgIHJldCA9IDEgKyBmdW4oaWRhKzEsIGlkYisxLCBpZGMpOwogICAgICAgIH0KICAgICAgICBlbHNlewogICAgICAgICAgICByZXQgPSBmdW4oaWRhKzEsIGlkYiwgaWRjKTsKICAgICAgICAgICAgcmV0ID0gbWF4KHJldCwgZnVuKGlkYSwgaWRiKzEsIGlkYykpOwogICAgICAgIH0KICAgIH0KICAgIGVsc2V7CiAgICAgICAgaWYoYVtpZGFdPT1iW2lkYl0pewogICAgICAgICAgICBpZihhW2lkYV09PWNbaWRjXSl7CiAgICAgICAgICAgICAgICByZXQgPSAxICsgZnVuKGlkYSsxLCBpZGIrMSwgaWRjKzEpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2V7CiAgICAgICAgICAgICAgICByZXQgPSBmdW4oaWRhKzEsIGlkYisxLCBpZGMpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGVsc2V7CiAgICAgICAgICAgIHJldCA9IGZ1bihpZGErMSwgaWRiLCBpZGMpOwogICAgICAgICAgICByZXQgPSBtYXgocmV0LCBmdW4oaWRhLCBpZGIrMSwgaWRjKSk7CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGRwW2lkYV1baWRiXVtpZGNdID0gcmV0Owp9CmludCBtYWluKCkKewogICAgaW50IHRjOwogICAgc2NhbmYoIiVkIiwmdGMpOwogICAgZm9yKGludCB0PTE7IHQ8PXRjOyB0KyspewogICAgICAgIHNjYW5mKCIlcyVzJXMiLGEsYixjKTsKICAgICAgICBsZW5hID0gc3RybGVuKGEpOwogICAgICAgIGxlbmIgPSBzdHJsZW4oYik7CiAgICAgICAgbGVuYyA9IHN0cmxlbihjKTsKICAgICAgICBtZW1zZXQoZHAsLTEsc2l6ZW9mIGRwKTsKICAgICAgICBwcmludGYoIkNhc2UgJWQ6ICVkXG4iLHQsbWF4KDAsZnVuKDAsMCwwKSkpOwogICAgfQogICAgcmV0dXJuIDA7Cn0K