eolymp
bolt
Try our new interface for solving problems
Problems

AND & OR & min on a segment

AND & OR & min on a segment

Vasyl has n integers: x1, x2,..., xn. You must help him to answer the queries of two types:

  1. AND L R - in this case find the minimum value xi1 AND xi2 AND ... AND xik, where {xik} is some nonempty subset, Li1 < i2 < ... < ikR, 1LRn.
  2. OR L R - in this case find the minimum value xi1 OR xi2 OR ... OR xik, where {xik} is some nonempty subset, Li1 < i2 < ... < ikR, 1LRn.

Input

The first line contains number n (1n100000). Next line contains n numbers xi (0xi109). Then the number of queries m (1m100000) is given. Each of the next m lines contains one query.

Output

For each query print the answer in separate line.

Time limit 1 second
Memory limit 128 MiB
Input example #1
5
1 2 3 4 5
4
AND 1 5
OR 1 5
AND 1 1
OR 3 4
Output example #1
0
1
1
3
Author Владимир Чих
Source Distance Summer Computer School - Summer 2013