import sys import bisect input = sys.stdin.readline n = int(input()) difficulty = [] type_map = {} for _ in range(n): a, b = map(int, input().split()) difficulty.append(a) if b not in type_map: type_map[b] = [] type_map[b].append(a) difficulty.sort() for k in type_map: type_map[k].sort() q = int(input()) for _ in range(q): x, y = map(int, input().split()) if x == 10**9: print(0) continue total = bisect.bisect_right(difficulty, x) blocked = bisect.bisect_right(type_map[y], x) if y in type_map else 0 print(total - blocked)