/***********************************
Problem: POJ 1080 Human Gene Functions
Time: 0MS
Memory: 176K
Accepted Time: 2009-08-07 16:05:15
Tip: 做过的题也不会做了 郁闷
http://hi.baidu.com/fandywang_jlu/blog/item/205d37f3c7e2d5c90a46e01a.html
************************************/
#include <stdio.h>
int table[5][5]={ 5,-1,-2,-1,-3,
-1, 5,-3,-2,-4,
-2,-3, 5,-2,-2,
-1,-2,-2, 5,-1,
-3,-4,-2,-1, 0};
int main()
{
int n,i,j;
int a[109][109];
char b[10]={"ACGT"};
scanf("%d",&n);
while(n--)
{
char str1[109],str2[109];
int len1,len2;
scanf("%d%s%d%s",&len1,str1+1,&len2,str2+1);
for(i=1;i<=len1;i++)
{
for(j=0;j<4;j++)
{
if(str1[i]==b[j])
{
str1[i]=j;
break;
}
}
}
for(i=1;i<=len2;i++)
{
for(j=0;j<4;j++)
{
if(str2[i]==b[j])
{
str2[i]=j;
break;
}
}
}
for(i=0;i<=len1;i++)
{
for(j=0;j<=len2;j++)
{
if(i==0&&j==0)a[i][j]=0;
else if(j==0&&i>0)a[i][j]=a[i-1][j]+table[str1[i]][4];
else if(i==0&&j>0)a[i][j]=a[i][j-1]+table[str2[j]][4];
else
{
a[i][j]=a[i-1][j-1]+table[str1[i]][str2[j]];
if(a[i][j]<a[i][j-1]+table[str2[j]][4])
a[i][j]=a[i][j-1]+table[str2[j]][4];
if(a[i][j]<a[i-1][j]+table[str1[i]][4])
a[i][j]=a[i-1][j]+table[str1[i]][4];
}
}
}
printf("%d/n",a[len1][len2]);
}
return 0;
}