//因为每个数都不同,可将A数组元素重新编号
//使得A数组为 1 - p+1 的数字
//删除B数组中 A没有的元素 求B数组的最长递增子序列长度 即为答案
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 250 * 250 + 7;
int idx[maxn], A[maxn], B[maxn], alen, blen, n;
int main()
{
int t;
cin >> t;
for (int kCase = 1; kCase <= t; kCase++) {
cin >> n >> alen >> blen;
memset(idx, 0, sizeof(idx));
int first = 1;
for (int i = 0; i <= alen; i++) {
cin >> A[i];
if (!idx[A[i]]) {
idx[A[i]] = first++;
}
}
int len = 0;
for (int i = 0; i <= blen; i++) {
cin >> B[len];
if (!idx[B[len]]) continue;
B[len] = idx[B[len]];
++len;
}
vector<int> dp = { B[0] };
for (int i = 1; i < len; ++i) {
if (B[i] > dp.back()) {
dp.emplace_back(B[i]);
}
else {
auto it = lower_bound(dp.begin(), dp.end(), B[i]);
*it = B[i];
}
}
cout << "Case " << kCase << ": " << dp.size() << endl;
}
return 0;
}