#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using namespace atcoder; #define rep(i,n,c) for (int i=0;i using vec = vector; template using vvec = vec>; template using vvvec = vec>; using ll = long long; using pii = pair; using pll = pair; template bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template bool chmax(T &a, T b){ if (a T sum(vec x){ T res=0; for (auto e:x){ res += e; } return res; } template void printv(vec x){ for (auto e:x){ cout< up){ //cout< ans){ return ans; } set one,two; rep(i,N,1){ if ((A[i]>>d) & 1){ if(up.find(i)!=up.end()){ two.insert(i); } else{ one.insert(i); } } else{ if (up.find(i)!=up.end()){ one.insert(i); } } } if ((one.size()&1)==((Y>>d)&1)){ res = min(res,dfs(d+1,tmp,two)); } if (((N-one.size())&1)==((Y>>d)&1)){ for (auto i:one){ two.insert(i); } res = min(res,dfs(d+1,tmp+((1ll)< a){ N = n; Y = y; rep(i,n,1){ A[i] = a[i]; } ans = (1ll)<<61; set S = {}; ll res = dfs(0,0,S); if (res < ((1ll)<<61)){ return res; } return -1; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; cin>>T; while (T--){ int n; cin>>n; ll y; cin>>y; vec a(n); rep(i,n,1){ cin>>a[i]; } cout<