You start with an empty list of numbers and process Q instructions in the order they are given.
insert N: put N into the list. The same number can arrive more than once.print: take the K largest numbers in the list and output their XOR sum. If the list holds fewer than K numbers, output the XOR sum of every number in the list, and if the list is empty, output 0.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] and K=2, the two chosen numbers are 5 and 5, so the XOR sum is 0.
XOR has a useful property: if N⊕M=X, then N=X⊕M and M=X⊕N.
The first line contains the number of test cases T (1≤T≤30).
The first line of each test case contains Q and K (1≤Q,K≤100000). The next Q lines each hold one instruction, in one of these two forms:
insert N
print
N is a non-negative integer smaller than 231.
For each print instruction, output the answer on its own line. The list starts empty again for every test case.