//Bismillahir Rahmanir Rahim
/******Harun Or Rashid******/
/***********Template Starts Here***********/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cassert>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))
#define ABS(a) ((a)>0? (a):(-(a)))
#define SQ(a) ((a)*(a))
#define SZ(a) (int)a.size()
#define FORN(i,n) for(i=1;i<=n;i++)
#define FORAB(i,a,b) for(i=a;i<=b;i++)
#define ALL(V) V.begin(),V.end()
#define pb(a) push_back(a)
#define pr(a) cout<<a<<endl
#define SQR(a) ((a)*(a))
#define pf printf
#define sf scanf
#define swap(a,b) (a ^= b, b ^= a, a ^= b)
#define PI acos(-1)
#define x first
#define y second
#define eps 1e-7
typedef int D;
typedef long long int LLD;
typedef unsigned long long int LLU;
typedef vector<D> VI;
typedef set<D> SI;
typedef vector<D>::iterator Viti;
/***********Template Ends Here***********/
int main()
{
int T,i,n,p,q,j,x,flag[62501];
cin>>T;
for(i=1; i<=T; i++)
{
cin>>n>>p>>q;
memset(flag,0,sizeof flag);
for(j=1; j<=p+1; j++)
{
cin>>x;
flag[x]=j;
}
vector<int>lcs;
for(j=1; j<=q+1; j++)
{
cin>>x;
if(flag[x]==0) continue;
if(lcs.size()==0 || lcs.back()<flag[x])
lcs.pb(flag[x]);
else *lower_bound(lcs.begin(),lcs.end(),flag[x])=flag[x];
}
printf("Case %d: %d\n",i,lcs.size());
}
return 0;
}
Ly9CaXNtaWxsYWhpciBSYWhtYW5pciBSYWhpbQovKioqKioqSGFydW4gT3IgUmFzaGlkKioqKioqLwovKioqKioqKioqKipUZW1wbGF0ZSBTdGFydHMgSGVyZSoqKioqKioqKioqLwojaW5jbHVkZTxpb3N0cmVhbT4KI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