from collections import defaultdict from sortedcontainers import SortedList N = int(input()) all = SortedList() for _ in range(N): a,b = list(map(int,input().split())) all.add((a,b,-1)) Q = int(input()) for i in range(Q): x,y = list(map(int,input().split())) all.add((x,y,i)) ans = [-1 for _ in range(Q)] bunya = defaultdict(int) prob_count = 0 for i in range(N+Q): a,b,c = all[i] if(c == -1): bunya[b] += 1 prob_count += 1 else: ans[c] = prob_count - bunya[b] for i in ans: print(i)