1. #include <bits/stdc++.h>
  2. using namespace std;
  3. /*
  4. ------------------------Input Checker----------------------------------
  5. */
  6. long long readInt(long long l,long long r,char endd){
  7. long long x=0;
  8. int cnt=0;
  9. int fi=-1;
  10. bool is_neg=false;
  11. while(true){
  12. char g=getchar();
  13. if(g=='-'){
  14. assert(fi==-1);
  15. is_neg=true;
  16. continue;
  17. }
  18. if('0'<=g && g<='9'){
  19. x*=10;
  20. x+=g-'0';
  21. if(cnt==0){
  22. fi=g-'0';
  23. }
  24. cnt++;
  25. assert(fi!=0 || cnt==1);
  26. assert(fi!=0 || is_neg==false);
  27. assert(!(cnt>19 || ( cnt==19 && fi>1) ));
  28. } else if(g==endd){
  29. if(is_neg){
  30. x= -x;
  31. }
  32. if(!(l <= x && x <= r))
  33. {
  34. cerr << l << ' ' << r << ' ' << x << '\n';
  35. assert(1 == 0);
  36. }
  37. return x;
  38. } else {
  39. assert(false);
  40. }
  41. }
  42. }
  43. string readString(int l,int r,char endd){
  44. string ret="";
  45. int cnt=0;
  46. while(true){
  47. char g=getchar();
  48. assert(g!=-1);
  49. if(g==endd){
  50. break;
  51. }
  52. cnt++;
  53. ret+=g;
  54. }
  55. assert(l<=cnt && cnt<=r);
  56. return ret;
  57. }
  58. long long readIntSp(long long l,long long r){
  59. return readInt(l,r,' ');
  60. }
  61. long long readIntLn(long long l,long long r){
  62. return readInt(l,r,'\n');
  63. }
  64. string readStringLn(int l,int r){
  65. return readString(l,r,'\n');
  66. }
  67. string readStringSp(int l,int r){
  68. return readString(l,r,' ');
  69. }
  70. /*
  71. ------------------------Main code starts here----------------------------------
  72. */
  73. const int MAX_T = 1e5;
  74. const int MAX_N = 1e5;
  75. const int MAX_SUM_LEN = 1e5;
  76. #define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  77. #define ff first
  78. #define ss second
  79. #define mp make_pair
  80. #define ll long long
  81. #define rep(i,n) for(int i=0;i<n;i++)
  82. #define rev(i,n) for(int i=n;i>=0;i--)
  83. #define rep_a(i,a,n) for(int i=a;i<n;i++)
  84. #define pb push_back
  85. int sum_n = 0, sum_m = 0;
  86. int max_n = 0, max_m = 0;
  87. int yess = 0;
  88. int nos = 0;
  89. int total_ops = 0;
  90. ll mod = 998244353;
  91.  
  92. using ii = pair<ll,ll>;
  93.  
  94.  
  95. void solve(){
  96.  
  97. int n = readIntSp(1,1e5);
  98. sum_n+=n;
  99. ll k = readIntLn(0, (1ll<<31)-1);
  100. k--;
  101.  
  102. ll a[n];
  103. rep(i,n-1) a[i] = readIntSp(0,(1<<30)-1);
  104. a[n-1] = readIntLn(0,(1<<30)-1);
  105.  
  106. if(k<0){
  107. cout<<1<<'\n';
  108. return;
  109. }
  110. unordered_map<ll,int> m[31];
  111. rep(i,31) m[i].insert(mp(0,-1));
  112.  
  113. int ans = n+1;
  114.  
  115. ll curr = 0;
  116. rep(i,n){
  117. if(a[i]>k){
  118. ans = 1;
  119. break;
  120. }
  121. curr^=a[i];
  122. ll z = 0;
  123. rev(j,30){
  124. z|=(1ll<<j);
  125. if(!((k>>j)&1)){
  126. ll tmp = (curr^k^(1ll<<j))&z;
  127. if(m[j].find(tmp)!=m[j].end()){
  128. ans = min(ans, i-m[j][tmp]);
  129. }
  130. }
  131. }
  132. z = 0;
  133. rev(j,30){
  134. z|=(1ll<<j);
  135. m[j][curr&z] = i;
  136. }
  137. }
  138.  
  139. if(ans>n) ans = -1;
  140. cout<<ans<<'\n';
  141.  
  142. }
  143.  
  144.  
  145. signed main()
  146. {
  147.  
  148. #ifndef ONLINE_JUDGE
  149. freopen("input.txt", "r" , stdin);
  150. freopen("output.txt", "w" , stdout);
  151. #endif
  152. fast;
  153. int t = 1;
  154. t = readIntLn(1,2e4);
  155. for(int i=1;i<=t;i++)
  156. {
  157. solve();
  158. }
  159. assert(getchar() == -1);
  160. assert(sum_n<=2e5);
  161. cerr<<"SUCCESS\n";
  162. cerr<<"Tests : " << t << '\n';
  163. cerr<<"Sum of lengths : " << sum_n<<'\n';
  164. //cerr<<"Maximum answer : " << max_n <<'\n';
  165. // // cerr<<"Total operations : " << total_ops << '\n';
  166. // cerr<<"Answered yes : " << yess << '\n';
  167. // cerr<<"Answered no : " << nos << '\n';
  168.  
  169. cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  170. }