Under construction

Still being built. Things may change

Interesting Numbers

Time limit3sMemory limit1024 MB

Summary
Given n integers and k, find the longest subsequence in which the XOR of every pair of elements is at most k.
Level

Medium7 of 10

Topics
Bit manipulation, Trie, Hash map
Solved
No attempts yet

Problem

The bitwise exclusive or, or simply XOR, is an operation denoted by ⊕\oplus that works on two integers by XOR-ing their corresponding bits. If xi,yi,zix_i, y_i, z_i denote the ii-th binary digit of xx, yy, and zz, where z=x⊕yz = x \oplus y, then zi=(xi+yi)mod  2z_i = (x_i + y_i) \mod 2.

You are given a positive integer kk. A sequence of integers is interesting if the XOR of any two of its elements is less than or equal to kk.

Given a sequence a1,…,ana_1, \dots, a_n, determine the largest possible length of an interesting subsequence. A subsequence is a sequence that can be derived from the given sequence by deleting zero or more elements.

Input

The first line contains the number of test cases zz (1≤z≤1 0001 \leq z \leq 1\,000). The descriptions of the test cases follow.

The first line of each case contains two integers nn and kk (1≤n≤30 0001 \leq n \leq 30\,000, 1≤k<2201 \leq k < 2^{20}), the length of the sequence and the upper bound on the maximum XOR of its two elements.

The second line contains nn nonnegative integers a1,…,ana_1, \dots, a_n (0≤ai<2200 \leq a_i < 2^{20}), the given sequence.

The sum of nn over all test cases does not exceed 200 000200\,000, and the sum of kk over all test cases does not exceed 3 200 0003\,200\,000.

Output

For every test case, output a single integer, the maximum possible length of an interesting subsequence of the given sequence.

Hint

The elements 3, 9, 10, and 3 form an interesting subsequence, since the XOR of every pair is at most 11. For example, 9⊕10=10012⊕10102=112=3≤119 \oplus 10 = 1001_2 \oplus 1010_2 = 11_2 = 3 \leq 11. No subsequence of five elements has this property. For example, (3,9,10,3,4)(3, 9, 10, 3, 4) is not interesting because 4⊕9=1002⊕10012=11012=13>114 \oplus 9 = 100_2 \oplus 1001_2 = 1101_2 = 13 > 11.

Examples1

  1. Example 1

    Input
    1
    7 11
    3 12 9 10 16 3 4
    
    Expected output
    4