inf = 10**18 class SegmentTree: # 初期化処理 # f : SegmentTreeにのせるモノイド # default : fに対する単位元 def __init__(self, size, f=lambda x,y : min(x,y), default=inf): self.size = 2**(size-1).bit_length() # 簡単のため要素数Nを2冪にする self.default = default self.dat = [default]*(self.size*2) # 要素を単位元で初期化 self.f = f def update(self, i, x): i += self.size self.dat[i] = x while i > 1: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def updatef(self, i, x): i += self.size self.dat[i] = self.f(self.dat[i],x) while i > 1: i >>= 1 self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1]) def query(self, l, r): l += self.size r += self.size lres, rres = self.default, self.default while l < r: if l & 1: lres = self.f(lres, self.dat[l]) l += 1 if r & 1: r -= 1 rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意 l >>= 1 r >>= 1 res = self.f(lres, rres) return res def query2(self): s = 1 #print(self.size) while sself.dat[s*2+1]: s = s*2 else: s = s*2+1 return s-self.size from collections import defaultdict n = int(input()) eve_in = defaultdict(list) eve_out = defaultdict(list) for i in range(n): l, r, a = map(int, input().split()) eve_in[l].append(a) eve_out[r].append(a) q = int(input()) eve_que = defaultdict(lambda:-1) x = list(map(int, input().split())) for i in range(q): eve_que[x[i]] = i ans = [-1] * q def f(x, y): if x[0] == x[1]: return x[0] + y[0], x[1] + y[1] return x[0], x[1] + y[1] st = SegmentTree(n, f, (0, 0)) for i in range(n): st.update(i, (0, 1)) cnt = [0] * n for x in sorted(set(list(eve_in)+list(eve_out)+list(eve_que))): for a in eve_in[x]: if a < n: cnt[a] += 1 if cnt[a] == 1: st.update(a, (1, 1)) if eve_que[x] != -1: ans[eve_que[x]] = st.query(0, n)[0] for a in eve_out[x]: if a < n: cnt[a] -= 1 if cnt[a] == 0: st.update(a, (0, 1)) for i in ans: print(i)