//Time 0ms, Memory 288K
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,la,lb,t,map[20][20],dp[105][105],x,y,z;
char a[105],b[105];
memset(map,0,sizeof(map));
map[0][0]=map[2][2]=map[6][6]=map[19][19]=5;
map[0][2]=map[2][0]=map[0][19]=map[19][0]=map[7][19]=-1;
map[0][6]=map[6][0]=map[2][19]=map[19][2]=map[6][19]=map[19][6]=map[7][6]=-2;
map[2][6]=map[6][2]=map[7][0]=-3;
map[7][2]=-4;
scanf("%d",&t);
while(t--)
{
scanf("%d%s%d%s",&la,a,&lb,b);
dp[0][0]=0;
for(i=1;i<=la;i++)
{
dp[i][0]=dp[i-1][0]+map[7][a[i-1]-65];
}
for(j=1;j<=lb;j++)
{
dp[0][j]=dp[0][j-1]+map[7][b[j-1]-65];
}
for(i=1;i<=la;i++)
{
for(j=1;j<=lb;j++)
{
x=dp[i-1][j-1]+map[a[i-1]-65][b[j-1]-65];
y=dp[i][j-1]+map[7][b[j-1]-65];
z=dp[i-1][j]+map[7][a[i-1]-65];
y=y>z?y:z;
dp[i][j]=x>y?x:y;
}
}
printf("%d\n",dp[la][lb]);
}
return 0;
}