Xorbonacci

Given the first K terms of an XOR recurrence, answer many queries asking for the XOR of terms l through r with indices up to 1e18.

Medium6MathPrefix sumBit manipulationNo attempts yetTime limit1sMemory limit64 MB

Problem

Marin swung a racket at flies so hard that he hurt his elbow. His grandmother told him to rub herbs on it and the doctor prescribed a painkiller, but Marin ignored both and went looking for an answer in integer sequences.

He built a new sequence and named it the xorbonacci sequence. Its nnth term is written xnx_n, and it is defined like this.

  • x1=a1x_1 = a_1
  • x2=a2x_2 = a_2
  • \dots
  • xk=akx_k = a_k
  • xn=xn1xn2xnkx_n = x_{n-1} \oplus x_{n-2} \oplus \dots \oplus x_{n-k} when n>kn > k

Marin says the pain goes away once someone answers his QQ queries. Each query gives two numbers ll and rr, and its answer is

xlxl+1xr1xrx_l \oplus x_{l+1} \oplus \dots \oplus x_{r-1} \oplus x_r

Here \oplus is the bitwise XOR operation.

Input

The first line contains the integer KK (1K1000001 \le K \le 100\,000).

The second line contains the first KK terms of the xorbonacci sequence. Every value is a nonnegative integer smaller than 101810^{18}.

The third line contains the integer QQ (1Q1061 \le Q \le 10^6).

The iith of the next QQ lines contains two integers lil_i and rir_i (1liri10181 \le l_i \le r_i \le 10^{18}) describing the iith query.

Output

Print QQ lines. The iith line holds the answer to the iith query of the input.