import sys from bisect import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines INF = 1 << 60 def main(V, query): def merge(A, B): NA, NB = len(A), len(B) i, j = 0, 0 C = [] for _ in range(NA + NB): if i == NA: C.append(B[j]) j += 1 elif j == NB: C.append(A[i]) i += 1 else: if A[i] > B[j]: C.append(B[j]) j += 1 else: C.append(A[i]) i += 1 return C N = len(V) seg = [[] for _ in range(N + N)] for i in range(N): seg[N + i] = [V[i]] for i in range(N - 1, 0, -1): seg[i] = merge(seg[i + i], seg[i + i + 1]) N = int(readline()) X = tuple(map(int, readline().split())) Q = int(readline()) m = map(int, read().split()) query = tuple(zip(m, m, m)) main(X, query)