AND & OR & min on a segment#4510

AND & OR & min on a segment

1 second
128 megabytes
Very easy

Vasyl has integers: x_1, x_2,..., x_N. You must help him to answer the queries of two types:

  1. AND L R - in this case find the minimum value x_{i_1} AND x_{i_2} AND ... AND x_{i_k}, where \{x_{i_k}\} is some nonempty subset, L \le i_1 < i_2 < ... < i_k \le R, 1 \le L \le R \le N.

  2. OR L R - in this case find the minimum value x_{i_1} OR x_{i_2} OR ... OR x_{i_k}, where \{x_{i_k}\} is some nonempty subset, L \le i_1 < i_2 < ... < i_k \le R, 1 \le L \le R \le N.

Input

The first line contains number , 1 \le N \le 100000. Next line contains numbers x_i, 0 \le x_i \le 10^9. Then the number of queries , 1 \le M \le 100000, is given. Each of the next lines contains one query.

Output

For each query print the answer in separate line.

Examples

Example 1

Loading
Loading