01字典树
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e6;
struct node
{
int root, p, Next[maxn][2];
void init(){
root = 0;
p = 0;
memset(Next,-1,sizeof(Next));
}
int newnode(){
p++;
return p;
}
void Insert(ll val){
int now = root;
for(int i = 32; i >= 0; i--){
int f = 0;
if((1ll<<i) & val) f = 1;
if(Next[now][f] == -1) Next[now][f] = newnode();
now = Next[now][f];
}
}
ll query(ll val){
ll res = 0; int now = root;
for(int i = 32; i >= 0; i--){
int f = 0;
if((1ll<<i) & val) f = 1;
if(Next[now][f^1] != -1){
res += ((ll)(f^1)<<i);
now = Next[now][f^1];
}
else{
now = Next[now][f];
res += ((ll)f<<i);
}
}
return res;
}
} trie;
int main()
{
int t, n, m; scanf("%d",&t);
ll x;
for(int mycase = 1; mycase <= t; mycase++){
scanf("%d%d",&n,&m);
trie.init();
for(int i = 1; i <= n; i++){
scanf("%I64d",&x);
trie.Insert(x);
}
printf("Case #%d:\n",mycase);
for(int i = 1; i <= m; i++){
scanf("%I64d",&x);
printf("%I64d\n",trie.query(x));
}
}
return 0;
}