#P9808. Or
Or
Or
Problem Description
DDOSvoid is learning about bitwise operations and has come across an interesting problem. You are given two sequences, and , both of length . Additionally, there are queries. In each query, you are given an interval . Your task is to calculate the bitwise OR operation on the following integers:$a_l, a_l+b_{l+1},a_{l}+b_{l+1}+b_{l+2},\cdots,a_{l+1}+b_{l+2},a_{l+1}+b_{l+2}+b_{l+3},\cdots,a_{r}$. In other words, you need to evaluate $\bigoplus_{i=l}^{r}\bigoplus_{j=i}^r(a_i+\sum_{k=i+1}^{j}b_k)$. The symbol represents the bitwise OR operation.
Input
The first line of the input contains a single integer , indicating the number of test cases. In each test case: The first line contains to integers . The second line contains integers . The third line contains integers . The next lines, each line contains two integers . It is guaranteed that in all test cases, .
Output
To simply the output, we use to represent the answer to the i-th query and . In each test case you just need to output an integer .
Sample Input
1
5 1
1 2 3 4 5
1 1 1 1 1
2 4
Sample Output
1631
Hint
For query , you need to calculate the bitwise OR operation on the following integers,
Source
2023“钉耙编程”中国大学生算法设计超级联赛(2)