import strutils, sequtils, algorithm proc getInts: auto = stdin.readLine.split.map parseInt let N = stdin.readLine.parseInt var person = newSeq[tuple[cost, taste: int]](N) for i in 0 ..< N: (person[i].cost, person[i].taste) = getInts() let M = stdin.readLine.parseInt var mentai = newSeq[tuple[cost, taste, pop: int]](M) for j in 0 ..< M: (mentai[j].cost, mentai[j].taste) = getInts() for i in 0 ..< N: if mentai[j].cost <= person[i].cost: if mentai[j].taste >= person[i].taste: mentai[j].pop += 1 let best = sortedByIt(mentai, -it.pop)[0].pop if best > 0: for j in 0 ..< M: if mentai[j].pop == best: echo j + 1 else: echo 0