from bisect import bisect_right from collections import defaultdict # Read number of problems N = int(input()) problems = [] field_diffs = defaultdict(list) for _ in range(N): A, B = map(int, input().split()) problems.append(A) field_diffs[B].append(A) # Sort difficulties globally and per field problems.sort() for key in field_diffs: field_diffs[key].sort() # Read number of people Q = int(input()) for _ in range(Q): X, Y = map(int, input().split()) # Count of problems with difficulty <= X total_easy = bisect_right(problems, X) # Count of problems in weak field Y with difficulty <= X bad = bisect_right(field_diffs[Y], X) if Y in field_diffs else 0 print(total_easy - bad)