#P17146. [ICPC 2017 Xi'an R] XOR

    ID: 19424 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>2017线段树线性基ST 表ICPC西安

[ICPC 2017 Xi'an R] XOR

Problem Description

Consider an array AA with nn elements. Each of its elements is A[i]A[i] (1in1 \le i \le n). Then two integers QQ, KK are given, and QQ queries follow. For each query, you are given LL, RR. You can get ZZ by the following rules.

To get ZZ, at first you need to choose some elements from A[L]A[L] to A[R]A[R], we call them A[i1],A[i2],,A[it]A[i_1], A[i_2], \dots, A[i_t]. Then you can get number Z=KZ = K or $(A[i_1] \text{ xor } A[i_2] \text{ xor } \dots \text{ xor } A[i_t])$.

Please calculate the maximum ZZ for each query.

Input Format

Several test cases.

First line an integer TT (1T101 \le T \le 10). Indicates the number of test cases. Then TT test cases follow. Each test case begins with three integers NN, QQ, KK ($1 \le N \le 10000,\ 1 \le Q \le 100000,\ 0 \le K \le 100000$). The next line has NN integers indicating A[1]A[1] to A[N]A[N] (0A[i]1080 \le A[i] \le 10^8). Then QQ lines follow, each line contains two integers LL, RR (1LRN1 \le L \le R \le N).

Output Format

For each query, print the answer in a single line.

1
5 3 0
1 2 3 4 5
1 3
2 4
3 5
3
7
7