#include <stdio.h> #include <stdlib.h> int arr[6][6]={ {0,0,0,0,0,0}, {0,5,-1,-2,-1,-3}, {0,-1,5,-3,-2,-4}, {0,-2,-3,5,-2,-2}, {0,-1,-2,-2,5,-1}, {0,-3,-4,-2,-1,-1000000}}; int dp[110][110]; int max3(int a,int b,int c) { int t; t= a>b?a:b; return t>c?t:c; } int main() { int T,len1,len2,i,j; char s1[110],s2[110]; int a[110],b[110]; scanf("%d",&T); while(T--) { scanf("%d%s%d%s",&len1,s1,&len2,s2); for(i=1;i<=len1;i++) { if(s1[i-1]=='A') a[i]=1; if(s1[i-1]=='C') a[i]=2; if(s1[i-1]=='G') a[i]=3; if(s1[i-1]=='T') a[i]=4; if(s1[i-1]=='-') a[i]=5; } for(i=1;i<=len2;i++) { if(s2[i-1]=='A') b[i]=1; if(s2[i-1]=='C') b[i]=2; if(s2[i-1]=='G') b[i]=3; if(s2[i-1]=='T') b[i]=4; if(s2[i-1]=='-') b[i]=5; } dp[0][0]=0; for(i=1;i<=len1;i++) dp[i][0]=dp[i-1][0]+arr[a[i]][5]; for(i=1;i<=len2;i++) dp[0][i]=dp[0][i-1]+arr[5][b[i]]; for(i=1;i<=len1;i++) { for(j=1;j<=len2;j++) { dp[i][j]=max3(dp[i-1][j-1]+arr[a[i]][b[j]],dp[i-1][j]+arr[a[i]][5],dp[i][j-1]+arr[5][b[j]]); } } printf("%d\n",dp[len1][len2]); } system("pause"); return 0; }