XOR Sum

No attempts yetTime limit2sMemory limit256 MB

Problem

You start with an empty list of numbers and process QQ instructions in the order they are given.

  • insert N: put NN into the list. The same number can arrive more than once.
  • print: take the KK largest numbers in the list and output their XOR sum. If the list holds fewer than KK numbers, output the XOR sum of every number in the list, and if the list is empty, output 00.

The XOR sum of a group of numbers is the result of XOR-ing all of them together. Most languages compute the XOR of two integers with the ^ operator. Haskell uses xor.

Equal values count as separate elements. If the list is [5,5,3][5, 5, 3] and K=2K = 2, the two chosen numbers are 55 and 55, so the XOR sum is 00.

XOR has a useful property: if NM=XN \oplus M = X, then N=XMN = X \oplus M and M=XNM = X \oplus N.

Input

The first line contains the number of test cases TT (1T301 \le T \le 30).

The first line of each test case contains QQ and KK (1Q,K1000001 \le Q, K \le 100\,000). The next QQ lines each hold one instruction, in one of these two forms:

insert N
print

NN is a non-negative integer smaller than 2312^{31}.

Output

For each print instruction, output the answer on its own line. The list starts empty again for every test case.