1. #include "bits/stdc++.h"
  2. // #pragma GCC optimize("O3,unroll-loops")
  3. // #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
  4. using namespace std;
  5. using ll = long long int;
  6. mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
  7.  
  8. int main()
  9. {
  10. ios::sync_with_stdio(false); cin.tie(0);
  11.  
  12. int t; cin >> t;
  13. while (t--) {
  14. int n, k; cin >> n >> k;
  15. vector<int> a(n);
  16. for (int &x : a) cin >> x;
  17. vector<int> b(n+1);
  18. for (int i = 1; i <= n; ++i) b[i] = a[i-1] ^ b[i-1];
  19.  
  20. int mask = INT_MAX, ans = n+1;
  21. auto calc = [&] (int target) {
  22. int pref = 0;
  23. map<int, int> last;
  24. last[0] = 0;
  25. for (int i = 0; i < n; ++i) {
  26. int x = a[i]&mask;
  27. pref ^= x;
  28. if (last.find(target^pref) != last.end()) ans = min(ans, i+1-last[target^pref]);
  29. last[pref] = i+1;
  30. }
  31. };
  32. calc(k);
  33. mask = 0;
  34. for (int bit = 30; bit >= 0; --bit) {
  35. mask += 1<<bit;
  36. if ((k>>bit)&1) continue;
  37. int target = k&mask; target |= 1<<bit;
  38. calc(target);
  39. }
  40.  
  41. if (ans == n+1) ans = -1;
  42. cout << ans << '\n';
  43. }
  44. }