from collections import defaultdict import bisect # Read number of problems N = int(input()) problems = [] for _ in range(N): A, B = map(int, input().split()) problems.append((A, B)) # Read number of people Q = int(input()) people = [] for _ in range(Q): X, Y = map(int, input().split()) people.append((X, Y)) # Sort problems by difficulty problems.sort() difficulties = [p[0] for p in problems] # Count number of problems in each field field_count = defaultdict(int) for _, b in problems: field_count[b] += 1 # Calculate easy problems for each person results = [] for X, Y in people: # Number of problems with difficulty <= X total_easy = bisect.bisect_right(difficulties, X) # Subtract problems in their weak field easy_count = total_easy - field_count.get(Y, 0) results.append(easy_count) # Output results for res in results: print(res)