#include <iostream>
#include <cstring>
using namespace std;
int T,N,M,K,dp[110][110][110]; char a[110],b[110];
int solve(int i, int j, int k){
if (k==0) return 0;
if (i==0 || j==0) return -(1<<30);
if (dp[i][j][k]!=-1) return dp[i][j][k];
int &ret=dp[i][j][k];
ret=-(1<<30);
if (a[i]==b[j]) ret=max(ret,a[i]+solve(i-1,j-1,k-1));
ret=max(ret,solve(i-1,j,k));
ret=max(ret,solve(i,j-1,k));
return ret;
}
int main(){
cin >> T;
int res;
while (T--){
cin >> (a+1);
a[0]='.';
cin >> (b+1);
b[0]='.';
cin >> K;
res=solve(N,M,K);
if (res<0) res=0;
cout << res << "\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBULE4sTSxLLGRwWzExMF1bMTEwXVsxMTBdOyBjaGFyIGFbMTEwXSxiWzExMF07CgppbnQgc29sdmUoaW50IGksIGludCBqLCBpbnQgayl7CiAgICBpZiAoaz09MCkgcmV0dXJuIDA7CiAgICBpZiAoaT09MCB8fCBqPT0wKSByZXR1cm4gLSgxPDwzMCk7CiAgICBpZiAoZHBbaV1bal1ba10hPS0xKSByZXR1cm4gZHBbaV1bal1ba107CgogICAgaW50ICZyZXQ9ZHBbaV1bal1ba107CiAgICByZXQ9LSgxPDwzMCk7CiAgICBpZiAoYVtpXT09YltqXSkgcmV0PW1heChyZXQsYVtpXStzb2x2ZShpLTEsai0xLGstMSkpOwogICAgcmV0PW1heChyZXQsc29sdmUoaS0xLGosaykpOwogICAgcmV0PW1heChyZXQsc29sdmUoaSxqLTEsaykpOwoKICAgIHJldHVybiByZXQ7Cn0KCmludCBtYWluKCl7CiAgICBjaW4gPj4gVDsKCiAgICBpbnQgcmVzOwogICAgd2hpbGUgKFQtLSl7CiAgICAgICAgY2luID4+IChhKzEpOwogICAgICAgIGFbMF09Jy4nOwogICAgICAgIGNpbiA+PiAoYisxKTsKICAgICAgICBiWzBdPScuJzsKICAgICAgICBOPXN0cmxlbihhKS0xOwogICAgICAgIE09c3RybGVuKGIpLTE7CiAgICAgICAgY2luID4+IEs7CiAgICAgICAgbWVtc2V0KGRwLC0xLHNpemVvZihkcCkpOwoKICAgICAgICByZXM9c29sdmUoTixNLEspOwogICAgICAgIGlmIChyZXM8MCkgcmVzPTA7CiAgICAgICAgY291dCA8PCByZXMgPDwgIlxuIjsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==