import sys input = sys.stdin.readline from collections import * def compress(l): l = list(set(l)) l.sort() idx = defaultdict(int) for i in range(len(l)): idx[l[i]] = i return idx class BIT: def __init__(self, n): self.n = n self.bit = [0]*(n+1) def add(self, i, x): i += 1 while i<=self.n: self.bit[i] += x i += i&(-i) def acc(self, i): s = 0 while i>0: s += self.bit[i] i -= i&(-i) return s N = int(input()) lra = [tuple(map(int, input().split())) for _ in range(N)] Q = int(input()) x = list(map(int, input().split())) idx = compress(x+[l for l, _, _ in lra]+[r for _, r, _ in lra]) d1 = defaultdict(list) for l, r, a in lra: d1[a].append((idx[l], idx[r])) d2 = defaultdict(list) for a in d1.keys(): now_l, now_r = d1[a][0] for l, r in d1[a][1:]: if l<=now_r: now_r = max(now_r, r) else: d2[a].append((now_l, now_r)) now_l, now_r = l, r d2[a].append((now_l, now_r)) al = list(sorted(d2.keys())) ok = [-1]*Q ng = [10**9+10]*Q while True: finish = True mid_idx = defaultdict(list) for i in range(Q): if abs(ok[i]-ng[i])>1: finish = False mid = (ok[i]+ng[i])//2 mid_idx[mid].append(i) if finish: break mids = list(sorted(mid_idx.keys(), reverse=True)) bit = BIT(len(idx.keys())) for a in al: while len(mids) and a>mids[-1]: mid = mids.pop() for i in mid_idx[mid]: ng[i] = mid for l, r in d2[a]: bit.add(l, 1) bit.add(r+1, -1) if len(mids) and a==mids[-1]: mid = mids.pop() for i in mid_idx[mid]: if bit.acc(idx[x[i]]+1)==a+1: ok[i] = mid else: ng[i] = mid while mids: mid = mids.pop() for i in mid_idx[mid]: ng[i] = mid for i in range(Q): print(ok[i]+1)