#K56437. Elevation Finder

    ID: 30198 Type: Default 1000ms 256MiB

Elevation Finder

Elevation Finder

You are given Q queries. For each query, you are provided with an array of elevation values and several segments. For each segment, identified by endpoints \(L\) and \(R\) (0-indexed and inclusive), you are required to determine the maximum and minimum elevations within that segment.

The input begins with an integer Q representing the number of queries. Then, for each query, a line with two integers N and P is given, where N is the number of elevation points, and P is the number of segments to process. This is followed by a line containing N integers representing the elevation values, and then P lines each containing two integers \(L\) and \(R\). For each segment, output the maximum and minimum elevation values separated by a space on a new line.

Example:

Input:
1
6 3
1 5 3 7 9 2
0 3
2 5
1 4

Output: 7 1 9 2 9 3

</p>

inputFormat

The input is given via standard input (stdin) and consists of multiple lines:

  1. The first line contains an integer Q, the number of queries.
  2. For each query, the first line contains two integers N and P separated by a space, where N is the number of elevations and P is the number of segments.
  3. The next line contains N integers representing the elevation values.
  4. This is followed by P lines, each containing two integers L and R (0-indexed), which describe a segment.

outputFormat

For each segment in each query, output a line containing two space-separated integers: the maximum elevation and the minimum elevation within that segment.

## sample
1
6 3
1 5 3 7 9 2
0 3
2 5
1 4
7 1

9 2 9 3

</p>