#include "bits/stdc++.h" // #pragma GCC optimize("O3,unroll-loops") // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; using ll = long long int; mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector<int> a(n); for (int &x : a) cin >> x; vector<int> b(n+1); for (int i = 1; i <= n; ++i) b[i] = a[i-1] ^ b[i-1]; int mask = INT_MAX, ans = n+1; auto calc = [&] (int target) { int pref = 0; map<int, int> last; last[0] = 0; for (int i = 0; i < n; ++i) { int x = a[i]&mask; pref ^= x; if (last.find(target^pref) != last.end()) ans = min(ans, i+1-last[target^pref]); last[pref] = i+1; } }; calc(k); mask = 0; for (int bit = 30; bit >= 0; --bit) { mask += 1<<bit; if ((k>>bit)&1) continue; int target = k&mask; target |= 1<<bit; calc(target); } if (ans == n+1) ans = -1; cout << ans << '\n'; } }