For an array and two positions , write
where is the bitwise AND.
You are given the array and then questions. Each one gives a starting position and a threshold , and asks for the largest with such that - that is, how far to the right the segment can be stretched before its AND drops below .
Input
First line of input will be a single integer - the number of testcases.
The first line of each testcase contains a single integer - the length of the array.
The second line contains integers .
The third line contains a single integer - the number of questions.
Each of the next lines contains two integers and - the starting position and the threshold.
Positions are counted from .
Output
For every testcase print one line holding the answers to its questions, in order, separated by spaces. If even is already below , print for that question.
Example
3 5 15 14 17 42 34 3 1 7 2 15 4 5 5 7 5 3 1 7 4 1 7 5 7 2 3 2 2 7 19 20 15 12 21 7 11 4 1 15 4 4 7 12 5 7
2 -1 5 1 5 2 2 2 6 -1 5
Take the first question of the first testcase. Starting at , the ANDs are , , and , so is the furthest that stays at or above. The second question starts at , where is already below , so the answer is .
Constraints
and
The sum of over all testcases does not exceed , and so does the sum of
This problem is based on Iva & Pav, problem 1878E from Codeforces Round 900, by Mike Mirzayanov and the Codeforces team. The statement here is our own.