#ds304. 异或第k小

异或第k小

XOR k-th Smallest

Problem Description

You are given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n.

You must answer mm queries. Each query gives two numbers xx and kk, and asks for the kk-th smallest element among a1⊕x,a2⊕x,…,an⊕xa_1 \oplus x, a_2 \oplus x, \dots, a_n \oplus x (sorted in ascending order).

Input Format

The first line contains two integers nn and mm.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n.

The following mm lines each contain two numbers xx and kk (1≤k≤n1 \le k \le n), representing one query.

Output Format

Output mm lines in total, each containing one integer: the kk-th smallest value for that query.

Sample Input

5 5
11 10 6 4 14
15 1
11 4
3 5
6 1
9 1

Sample Output

1
13
13
0
2

Constraints

For 100%100\% of the test data: 1≤n,m≤2×1051 \le n, m \le 2 \times 10^5, 0≤ai,x≤230−10 \le a_i, x \le 2^{30} - 1.