#P1771F. Hossam and Range Minimum Query

    ID: 8123 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>binary searchbitmasksdata structureshashingprobabilitiesstringstrees*2500

Hossam and Range Minimum Query

No submission language available for this problem.

Description

Hossam gives you a sequence of integers a1,a2,,ana_1, \, a_2, \, \dots, \, a_n of length nn. Moreover, he will give you qq queries of type (l,r)(l, \, r). For each query, consider the elements al,al+1,,ara_l, \, a_{l + 1}, \, \dots, \, a_r. Hossam wants to know the smallest number in this sequence, such that it occurs in this sequence an odd number of times.

You need to compute the answer for each query before process the next query.

The first line of the input contains one integer nn (1n21051 \le n \le 2 \cdot 10^5), the length of the sequence.

The second line contains nn integers a1,a2,,ana_1, \, a_2, \, \dots, \, a_n (1ai1091 \le a_i \le 10^9).

The third line contains one integer qq (1q21051 \le q \le 2 \cdot 10^5), the number of queries.

Each of the next qq lines contains two integers aa and bb (0a,b21090 \le a, \, b \le 2 \cdot 10^9), the numbers used to encode the queries.

Let ansi\mathrm{ans}_i be the answer on the ii-th query, and ans0\mathrm{ans}_0 be zero. Then li=aiansi1,l_i = a_i \oplus \mathrm{ans}_{i - 1}, ri=biansi1,r_i = b_i \oplus \mathrm{ans}_{i - 1}, where li,ril_i, \, r_i are parameters of the ii-th query and \oplus means the bitwise exclusive or operation. It is guaranteed that 1lrn1 \le l \le r \le n.

For each query, print the smallest number that occurs an odd number of times on the given segment of the sequence.

If there is no such number, print 00.

Input

The first line of the input contains one integer nn (1n21051 \le n \le 2 \cdot 10^5), the length of the sequence.

The second line contains nn integers a1,a2,,ana_1, \, a_2, \, \dots, \, a_n (1ai1091 \le a_i \le 10^9).

The third line contains one integer qq (1q21051 \le q \le 2 \cdot 10^5), the number of queries.

Each of the next qq lines contains two integers aa and bb (0a,b21090 \le a, \, b \le 2 \cdot 10^9), the numbers used to encode the queries.

Let ansi\mathrm{ans}_i be the answer on the ii-th query, and ans0\mathrm{ans}_0 be zero. Then li=aiansi1,l_i = a_i \oplus \mathrm{ans}_{i - 1}, ri=biansi1,r_i = b_i \oplus \mathrm{ans}_{i - 1}, where li,ril_i, \, r_i are parameters of the ii-th query and \oplus means the bitwise exclusive or operation. It is guaranteed that 1lrn1 \le l \le r \le n.

Output

For each query, print the smallest number that occurs an odd number of times on the given segment of the sequence.

If there is no such number, print 00.

Sample Input 1

5
1 2 1 2 2
6
1 2
0 2
0 6
0 5
2 2
3 7

Sample Output 1

1
2
1
0
2
2

Sample Input 2

10
51 43 69 48 23 52 48 76 19 55
10
1 1
57 57
54 62
20 27
56 56
79 69
16 21
18 30
25 25
62 61

Sample Output 2

51
55
19
48
76
19
23
19
55
19

Note

In the example,

l1=1,r1=2,l_1 = 1, \, r_1 = 2, l2=1,r2=3,l_2 = 1, \, r_2 = 3, l3=2,r3=4,l_3 = 2, \, r_3 = 4, l4=1,r4=4,l_4 = 1, \, r_4 = 4, l5=2,r5=2,l_5 = 2, \, r_5 = 2, l6=1,r6=5.l_6 = 1, \, r_6 = 5.