import std.stdio, std.string, std.array, std.conv, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    int[] a = readln.chomp.split.to!(int[]);
    int q = readln.chomp.to!int;
    foreach (i; 0 .. q) {
        int[] tmp = readln.chomp.split.to!(int[]);
        int c = tmp[0], b = tmp[1], e = tmp[2];
        if (c) a[b..e].dup.sort.array[$-1].writeln;
        else a[b..e].dup.sort.array[0].writeln;
    }
}
