// Author: Param Singh <paramsingh258@gmail.com>
// http://www.spoj.com/problems/SUBXOR/
import java.io.*;
class Trie {
    private class Node {
        int val;
        Node children[];
        Node() {
            val = 0;
            children = new Node[2];
            children[0] = null;
            children[1] = null;
        }
    }

    private Node root;

    Trie() {
        root = new Node();
    }

    private void insert(Node vertex, int n, int bits) {
        if (bits == 0) {
            vertex.val++;
            return;
        }
        else {
            int bit = (n >> (bits-1)) & 1;
            if (vertex.children[bit] == null) {
                vertex.children[bit] = new Node();
            }
            insert(vertex.children[bit], n, bits-1);
        }
    }

    public void insert(int n) {
        insert(root, n, 32);
    }

    private int query(Node vertex, int n, int k, int bits) {
        if (bits == 0) {
            if (k <= 0)
                return 0;
            else
                return vertex.val;
        }
        else {
            int v = (n >> (bits - 1)) & 1;
            int r = (v == 0) ? 1 : 0;
            int a = 0, b = 0;
            if (vertex.children[v] != null)
                a = query(vertex.children[v], n, k, bits-1);
            if (vertex.children[r] != null)
                b = query(vertex.children[r], n, k - (int) Math.pow(2, bits-1), bits-1);
            return a + b;
        }
    }

    public int query(int n, int k) {
        return query(root, n, k, 32);
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int t = Integer.parseInt(in.readLine());
        for (int a = 0; a < t; a++) {
            Trie trie = new Trie();
            String s[] = in.readLine().split(" ");
            int size = Integer.parseInt(s[0]), k = Integer.parseInt(s[1]);
            String s1[] = in.readLine().split(" ");
            int ans = 0, p = 0, q;
            for (int i = 0; i < size; i++) {
                int n = Integer.parseInt(s1[i]);
                q = p ^ n;
                ans += trie.query(q, k);
                trie.insert(q);
                p = q;
            System.out.println(ans);
            }
        }
    }
}

@@ -151,24 +151,43 @@
    int val;%0A
+        int num%5B%5D;%0A
         Node
@@ -273,16 +273,94 @@
 ode%5B2%5D;%0A
+            num = new int%5B2%5D;%0A            num%5B0%5D = 0;%0A            num%5B1%5D = 0;%0A
         
@@ -492,24 +492,43 @@
 new Node();%0A
+        insert(0);%0A
     %7D%0A%0A    p
@@ -607,34 +607,8 @@
 ) %7B%0A
-            vertex.val++;%0A
     
@@ -683,32 +683,63 @@
  (bits-1)) & 1;%0A
+            vertex.num%5Bbit%5D++;%0A
             if (
@@ -1058,144 +1058,85 @@
  == 
-0) %7B%0A            if (k %3C= 0)%0A                return 0;%0A            else%0A                return vertex.val;%0A        %7D%0A        else %7B%0A    
+-1 %7C%7C vertex == null)%0A            return 0;%0A        int p = (n %3E%3E bits) & 1;%0A
     
@@ -1147,28 +1147,22 @@
 int 
-v
+q
  = (
-n
+k
  %3E%3E 
-(
 bits
- - 1)
 ) & 
@@ -1176,37 +1176,21 @@
     
-    int r = (v
+if (q
  == 
-0) ? 1 : 0;
+1) %7B
 %0A   
@@ -1203,25 +1203,22 @@
    i
-nt a
+f (p
  =
+=
  0
-, b = 0;%0A
+)%0A   
     
@@ -1229,59 +1229,128 @@
     
-if (vertex.children%5Bv%5D != null)%0A                a =
+ return vertex.num%5B0%5D + query(vertex.children%5B1%5D, n, k, bits-1);%0A            else%0A                return vertex.num%5B1%5D +
  que
@@ -1368,17 +1368,17 @@
 hildren%5B
-v
+0
 %5D, n, k,
@@ -1381,32 +1381,55 @@
 , k, bits-1);%0A  
+      %7D%0A        else %7B%0A
           if (ve
@@ -1426,38 +1426,20 @@
     
+  
 if (
-vertex.children%5Br%5D != null
+p == 0
 )%0A  
@@ -1456,11 +1456,14 @@
     
-b =
+return
  que
@@ -1485,79 +1485,110 @@
 ren%5B
-r
+0
 %5D, n, k
- - (int) Math.pow(2, bits-1), bits-1);%0A            return a + b
+, bits - 1);%0A            else%0A                return query(vertex.children%5B1%5D, n, k, bits - 1)
 ;%0A  
@@ -1673,17 +1673,17 @@
  n, k, 3
-2
+1
 );%0A    %7D
@@ -1760,24 +1760,27 @@
     
-Buffered
+InputStream
 Reader i
 n = 
@@ -1779,35 +1779,17 @@
 er i
-n
+sr
  = new 
-BufferedReader(new 
 Inpu
@@ -1812,16 +1812,68 @@
 stem.in)
+;%0A        BufferedReader in = new BufferedReader(isr
 );%0A     
@@ -2188,25 +2188,42 @@
 int 
-ans
+p
  = 0, 
-p
+q;%0A            long ans
  = 0
-, q
 ;%0A  
@@ -2433,24 +2433,38 @@
      p = q;%0A
+            %7D%0A
             
@@ -2488,30 +2488,16 @@
 n(ans);%0A
-            %7D%0A
         

Correct answer for SUBXOR