#include <cstdio> #include <cstring> #include <queue> #include <cmath> #include <algorithm> #include <iostream> #include <cstdlib> #define lson l,mid,o<<1 #define rson mid + 1,r ,o<<1|1 using namespace std; int s1[1010],s2[1010]; int dp[1010]; int t,n1,n2; void lics() { int i,j,k; for(i=1;i<=n1;i++) { int maxx=0; for(j=1;j<=n2;j++) { if(s1[i]==s2[j]) { dp[j]=maxx+1; } else if(s1[i]>s2[j]&&maxx<dp[j]) { maxx=dp[j]; } } } } int main() { int i,j,k; scanf("%d",&t); while(t--) { memset(dp,0,sizeof(dp)); scanf("%d",&n1); for(i=1;i<=n1;i++) { scanf("%d",&s1[i]); } scanf("%d",&n2); for(i=1;i<=n2;i++) { scanf("%d",&s2[i]); } lics(); int ans=0; for(j=1;j<=n2;j++) { if(dp[j]>ans) ans=dp[j]; } printf("%d ",ans); } return 0; }