#include<bits/stdc++.h> using namespace std; const int maxn=1e6+7; typedef long long ll; inline ll read(){ ll s = 0, w = 1; char ch = getchar(); while (ch < 48 || ch > 57) { if (ch == '-') w = -1; ch = getchar(); } while (ch >= 48 && ch <= 57) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar(); return s * w; } bool f[101][101][101][101]; char a[101],b[101]; int main() { int t; scanf("%d",&t); while(t--) { int ans=0; scanf("%s%s",a+1,b+1); int n=strlen(a+1),m=strlen(b+1),j,l; for(int len1=0;len1<=n;++len1) for(int len2=0;len2<=m;++len2) for(int i=1;i+len1-1<=n;++i) for(int k=1;k+len2-1<=m;++k) { j=i+len1-1,l=k+len2-1; if(len1+len2<=1) f[i][j][k][l]=true; else{ f[i][j][k][l]=false; if(len1>1) f[i][j][k][l]|=(f[i+1][j-1][k][l]&&a[i]==a[j]); if(len1&&len2) f[i][j][k][l]|=(f[i+1][j][k][l-1]&&a[i]==b[l])|(f[i][j-1][k+1][l]&&a[j]==b[k]); if(len2>1) f[i][j][k][l]|=(f[i][j][k+1][l-1]&&b[k]==b[l]); } if(f[i][j][k][l]) ans=max(ans,len1+len2); } printf("%d\n",ans); } }