01Trie
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef struct Node{
private:
bool exist;
Node *_next[2];
Node(){
exist = false;
memset(_next, 0, sizeof(_next));
}
Node *create(){
Node *cur = (Node *)malloc(sizeof(Node));
cur ->init();
return cur;
}
public:
void init(){
exist = false;
memset(_next, 0, sizeof(_next));
}
Node *next(int x){
if(!_next[x]) _next[x] = create();
return _next[x];
}
int traverse(int x){
if(_next[x]) return x;
return x ^ 1;
}
Node *get_next(int x){
return _next[x];
}
void stop(){
exist = true;
}
}Node;
typedef struct Trie{
Node *root;
Trie(){
root = (Node *)malloc(sizeof(Node));
root ->init();
}
void insert(ll x){
Node *cur = root;
for(int i = 32; i >= 0; i--) cur = cur ->next(x & (1LL << i) ? 1 : 0);
cur ->stop();
}
ll xor_max(ll x){
ll res = 0;
Node *cur = root;
for(int i = 32; i >= 0; i--){
//printf("i = %d, res = %lld\n", i, res);
ll next = x & (1LL << i) ? 0 : 1;
next = cur ->traverse(next);
cur = cur ->get_next(next);
if(!cur) return res;
res += next * (1LL << i);
}
return res;
}
}Trie;
int main(void)
{
int times; scanf("%d", ×);
for(int i = 1; i <= times; i++){
printf("Case #%d:\n", i);
Trie t;
int n, m;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++){
ll x;
scanf("%lld", &x);
t.insert(x);
}
while(m--){
ll x;
scanf("%lld", &x);
printf("%lld\n", t.xor_max(x));
}
}
return 0;
}