1. #define ll long long
  2. #define pub push_back
  3. #define pob pop_back
  4. #define puf push_front
  5. #define pof pop_front
  6. #define mp make_pair
  7. #define fo(i , n) for(ll i = 0 ; i < n ; i++)
  8. //#include<bits/stdc++.h>
  9. #include<iomanip>
  10. #include<cmath>
  11. #include<cstdio>
  12. #include<utility>
  13. #include<iostream>
  14. #include<vector>
  15. #include<string>
  16. #include<algorithm>
  17. #include<map>
  18. #include<queue>
  19. #include<set>
  20. #include<stack>
  21. ll pi = acos(-1) ;
  22. ll z = 1000000007 ;
  23. ll inf = 100000000000000000 ;
  24. ll p1 = 37 ;
  25. ll p2 = 53 ;
  26. ll mod1 = 202976689 ;
  27. ll mod2 = 203034253 ;
  28. const int NN = 3e2 ;
  29. ll fact[NN];
  30. ll gdp(ll a , ll b){return (a - (a%b)) ;}
  31. ll ld(ll a , ll b){if(a < 0) return -1*gdp(abs(a) , b) ; if(a%b == 0) return a ; return (a + (b - a%b)) ;} // least number >=a divisible by b
  32. ll gd(ll a , ll b){if(a < 0) return(-1 * ld(abs(a) , b)) ; return (a - (a%b)) ;} // greatest number <= a divisible by b
  33. ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
  34. ll e_gcd(ll a , ll b , ll &x , ll &y){ if(b > a) return e_gcd(b , a , y , x) ; if(b == 0){x = 1 ; y = 0 ; return a ;}
  35. ll x1 , y1 ; e_gcd(b , a%b , x1 , y1) ; x = y1 ; y = (x1 - ((a/b) * y1)) ; return e_gcd(b , a%b , x1 , y1) ;}
  36. ll power(ll a ,ll b , ll p){if(b == 0) return 1 ; ll c = power(a , b/2 , p) ; if(b%2 == 0) return ((c*c)%p) ; else return ((((c*c)%p)*a)%p) ;}
  37. ll inverse(ll a ,ll n){return power(a , n-2 , n) ;}
  38. ll max(ll a , ll b){if(a > b) return a ; return b ;}
  39. ll min(ll a , ll b){if(a < b) return a ; return b ;}
  40. ll left(ll i){return ((2*i)+1) ;}
  41. ll right(ll i){return ((2*i) + 2) ;}
  42. ll ncr(ll n , ll r){if(n < r) return 0 ; return ((((fact[n] * inverse(fact[r] , z)) % z) * inverse(fact[n-r] , z)) % z);}
  43. void swap(ll&a , ll&b){ll c = a ; a = b ; b = c ; return ;}
  44. //ios_base::sync_with_stdio(0);
  45. //cin.tie(0); cout.tie(0);
  46. using namespace std ;
  47. #include <ext/pb_ds/assoc_container.hpp>
  48. #include <ext/pb_ds/tree_policy.hpp>
  49. using namespace __gnu_pbds;
  50. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  51. #define pll pair<ll, ll>
  52. // ordered_set s ; s.order_of_key(val) no. of elements strictly less than val
  53. // s.find_by_order(i) itertor to ith element (0 indexed)
  54. //__builtin_popcount(n) -> returns number of set bits in n
  55.  
  56.  
  57. ll get_ans(ll n, ll arr[] , ll bits, ll val)
  58. {
  59. ll ans = inf ;
  60. map<ll ,ll> m ;
  61.  
  62. ll curr_arr[n] ;
  63. for(int i = 0 ; i < n ; i++)
  64. {
  65. curr_arr[i] = ((arr[i]) >> (int)bits) ;
  66. }
  67.  
  68. ll pre_xor = 0 ;
  69. m[0] = -1 ;
  70. for(int i = 0 ; i < n ; i++)
  71. {
  72. pre_xor ^= curr_arr[i] ;
  73. ll req_xor = (val ^ pre_xor) ;
  74.  
  75. if(m.find(req_xor) == m.end())
  76. {
  77. m[pre_xor] = i ;
  78. continue ;
  79. }
  80.  
  81. ll curr_ans = (i - m[req_xor]) ;
  82. ans = min(ans , curr_ans) ;
  83. m[pre_xor] = i ;
  84. }
  85. return ans ;
  86.  
  87. }
  88.  
  89. void solve()
  90. {
  91. ll n, k ;
  92. cin >> n >> k ;
  93.  
  94. ll arr[n] ;
  95. for(int i = 0 ; i < n ; i++)
  96. cin >> arr[i] ;
  97.  
  98. ll curr_val = 0 ;
  99. ll ans = inf ;
  100.  
  101. for(int i = 31 ; i >= 0 ; i--)
  102. {
  103. ll bit = ((1LL << i) & k) ;
  104. // cout << "bit = " << bit << endl ;
  105. curr_val *= 2 ;
  106.  
  107. if(bit != 0)
  108. {
  109. curr_val++ ;
  110. continue ;
  111. }
  112.  
  113. ans = min(ans , get_ans(n , arr , i , curr_val+1)) ;
  114. // cout << "i = " << i << " ans = " << ans << '\n' << endl ;
  115. }
  116. ans = min(ans , get_ans(n , arr , 0 , k)) ;
  117.  
  118. if(ans == inf)
  119. ans = -1 ;
  120. cout << ans << endl ;
  121. }
  122.  
  123. int main()
  124. {
  125. ios_base::sync_with_stdio(0);
  126. cin.tie(0); cout.tie(0);
  127. #ifndef ONLINE_JUDGE
  128. freopen("inputf.txt" , "r" , stdin) ;
  129. freopen("outputf.txt" , "w" , stdout) ;
  130. freopen("errorf.txt" , "w" , stderr) ;
  131. #endif
  132. ll t = 1;
  133. cin >> t ;
  134. while(t--)
  135. {
  136. solve() ;
  137. }
  138. // cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  139. return 0;
  140. }