class ClubMember: buy = {} def __init__(self,budget,hot): self.budget = budget self.hot = hot def choice(self,number,price,hot): if price <= self.budget and hot >= self.hot: ClubMember.buy.setdefault(number,0) ClubMember.buy[number]+=1 @classmethod def miracle_mentaiko(cls): if not cls.buy: return [] popular = max(cls.buy.values()) return sorted([x for x,y in cls.buy.items() if y == popular]) N = int(input()) members = [ClubMember(*map(int,input().split())) for x in range(N)] M = int(input()) for i in range(M): price,hot = map(int,input().split()) for member in members: member.choice(i + 1,price,hot) miracle = ClubMember.miracle_mentaiko() if miracle: for i in miracle: print(i) else: print(0)