A certain kingdom is preparing for war. Its army consists mainly of cannons, and the tactics for using them are very simple. The kingdom owns n cannons. During a battle they are placed one after another along the front line. The cannons are numbered from 1 to n, from left to right. Each cannon i has an associated integer pi denoting its combat strength.
The Royal Combat Analysis Center (CAB) is responsible for battle tactics. While preparing for war, CAB considers various battle scenarios. A scenario assumes that the front is attacked along the segment from cannon a to cannon b. To choose the most effective tactic, CAB needs to know the minimum and maximum combat strength among the cannons on that segment. Help CAB solve this quickly.
The first line contains a natural number d (1≤d≤100), the number of tests. The descriptions of the tests follow one after another.
The first line of each test contains an integer n (1≤n≤106), the number of cannons. The second line contains n integers pi (−109≤pi≤109), the combat strengths of the cannons. The next line contains an integer m (1≤m≤105), the number of scenarios CAB considers. Each of the following m lines contains one scenario, given as two integers a and b (1≤a≤b≤n).
For each scenario, print the minimum and the maximum combat strength among the cannons on the segment from cannon a to cannon b, separated by a single space on one line.