#codefestivalchinaj. [code_festival_china_j]XORAND

[code_festival_china_j]XORAND

Problem

Yu loves bitwise AND operation and big number. Yu's friend Yihuo loves bitwise XOR operation and small number. They are good friends that whenever someone sends them an array of numbers as a gift, they share the numbers with each other.

For an array of non-negative integers p1,p2,...,pkp_1, p_2, ..., p_k, let DD be the result of bitwise AND between all numbers in the array (p1p_1rmAND\\rm{\\ AND\\ }p2p_2rmAND\\rm{\\ AND\\ }......rmAND\\rm{\\ AND\\ }pkp_k), and let XX be the result of bitwise XOR between all numbers in the array (p1p_1rmXOR\\rm{\\ XOR\\ }p2p_2rmXOR\\rm{\\ XOR\\ }......rmXOR\\rm{\\ XOR\\ }pkp_k). Yu's satisfaction value for p1,p2,...,pkp_1, p_2, ..., p_k is DD, Yihuo's satisfaction value for the same array of numbers is \-X\-X (Note that Yihuo loves small number. The less XX is, the more Yihuo satisfies.)

Whenever they receive an array of non-negative integer p1,p2,...,pkp_1, p_2, ..., p_k as a gift, they cut the array in the middle and Yu gets the former part, Yihuo gets the latter part. The place they cut the array is determined to maximize the sum of each satisfaction value for the array each get. To say more precisely, they cut the array at after the ii-th number within 1leqi<k1 \\leq i < k, which maximizes the sum of Yu's satisfaction value for p1,p2,...,pip_1, p_2, ..., p_i and Yihuo's satisfaction value for pi+1,pi+2,...,pkp_{i+1}, p_{i+2}, ..., p_k.

You will be given a NN elements non-negative integer array AA and QQ numbers of query. The jj-th query asks "How much is the sum of their satisfaction value when we give Alj,Alj+1,...,ArjA_{l_j}, A_{l_j+1}, ..., A_{r_j} to Yu and Yihuo". Your task is to answer all queries in the given order.

Note that each query is described by 22 integers lj,rjl_j, r_j (1leqlj<rjleqN1 \\leq l_j < r_j \\leq N), but those integers are not given directly. You must calculate those 22 integers from the last query's answer as described in the Input section. This means that you must calculate the answer of queries in the given order.


Input

NN QQ A1A_1 A2A_2 ... ANA_N l1l'_1 r1r'_1 l2l'_2 r2r'_2 : lQl'_Q rQr'_Q

  • On the first line, you will be given two integers NN (2leqNleq1052 \\leq N \\leq 10^5), QQ (1leqQleq1051 \\leq Q \\leq 10^5) separated by space, the number of elements in the array AA and the number of queries respectively.
  • On the second line, you will be given NN integers separated by space. The ii-th (1leqileqN1 \\leq i \\leq N) integer is AiA_i (0leqAi<2310 \\leq A_i < 2^{31}).
  • Following QQ lines are the information of the query. The jj-th (1leqjleqQ1 \\leq j \\leq Q) line contains 22 integers ljl'_j (1leqljleqN1 \\leq l'_j \\leq N), rjr'_j (1leqrjleqN1 \\leq r'_j \\leq N) separated by space.

Calculate ljl_j, rjr_j, the exact integers in the query as following.

  • l1=l1l_1 = l'_1, r1=r1r_1 = r'_1
  • For all jj that satisfies 2jQ2 ≦ j ≦ Q, let mj1m_{j - 1} be the answer to the (j1)(j - 1)-th query.
    • lj=((lj+mj1)l_j = ((l'_j + \\|m_{j - 1}\\|)rmMOD\\rm{\\ MOD\\ }N)+1N) + 1
    • rj=((rj+mj1)r_j = ((r'_j + \\|m_{j - 1}\\|)rmMOD\\rm{\\ MOD\\ }N)+1N) + 1

Note that each answer may be a negative number that the absolute value of mj1m_{j - 1} is used to obtain ljl_j and rjr_j. It is guaranteed that 1leqlj<rjleqN1 \\leq l_j < r_j \\leq N holds.

Output

Output QQ lines. The jj-th (1leqjleqQ1 \\leq j \\leq Q) line should contain the answer to the jj-th query. Make sure to insert a line break at the end of the output.


Input Example 1


7 4
7 3 5 4 6 3 1
2 5
2 5
3 4
5 1

Output Example 1


-1
2
2
5

The answer to each query is as following.

  • For the first query, l1=2l_1 = 2, r1=5r_1 = 5. The array of numbers 3,5,4,63, 5, 4, 6 will be separated to 3,53, 5 and 4,64, 6, which provides Yu's satisfaction value 33 AND 5=15 = 1, Yihuo's satisfaction value \-(4\-(4 XOR 6)=26) = -2, summed up to \-1\-1.
  • For the second query, l2=(2+1)l_2 = (2 + \\|-1\\|) MOD 7+1=47 + 1 = 4, r2=(5+1)r_2 = (5 + \\|-1\\|) MOD 7+1=77 + 1 = 7. The array 4,6,3,14, 6, 3, 1 will be separated to 4,64, 6 and 3,13, 1, which provides Yu's satisfaction value 44 AND 6=46 = 4 and Yihuo's satisfaction value \-(3\-(3 XOR 1)=21) = -2, summed up to 22.
  • For the third query, l3=(3+2)l_3 = (3 + \\|2\\|) MOD 7+1=67 + 1 = 6, r3=(4+2)r_3 = (4 + \\|2\\|) MOD 7+1=77 + 1 = 7. The array 3,13, 1 can only be separated to 33 and 11, which provides Yu's satisfaction value 33 and Yihuo's satisfaction value \-1\-1, summed up to 22.
  • For the fourth query, l4=(5+2)l_4 = (5 + \\|2\\|) MOD 7+1=17 + 1 = 1, r4=(1+2)r_4 = (1 + \\|2\\|) MOD 7+1=47 + 1 = 4. The array 7,3,5,47, 3, 5, 4 will be separated to 77 and 3,5,43, 5, 4, which provides Yu's satisfaction value 77 and Yihuo's satisfaction value \-(3\-(3 XOR 55 XOR 4)=24) = -2, summed up to 55.

Input Example 2


20 30
1 4 3 6 9 9 6 7 5 3 5 4 9 4 1 2 14 5 11 1
14 18
4 15
2 10
3 13
20 15
7 12
18 10
9 15
20 12
5 7
6 10
8 12
4 14
17 11
15 16
17 7
20 13
8 9
14 17
13 16
5 6
4 11
5 7
4 6
12 16
16 15
13 16
2 7
8 15
10 16

Output Example 2


-4
-1
0
-2
-1
-4
-1
4
3
-1
3
-2
6
3
10
5
1
-2
-1
-5
1
-6
-4
-1
-4
0
-9
4
3
2

The lil_i, rir_i for each query is as following.


14 18
9 20
4 12
4 14
3 18
9 14
3 15
11 17
5 17
9 11
8 12
12 16
7 17
4 18
19 20
8 18
6 19
10 11
17 20
15 18
11 12
6 13
12 14
9 11
14 18
1 20
14 17
12 17
13 20
14 20