t = int(input())
for i in range(t):
bus = [0] * (5000+1)
n = int(input())
for j in range(n):
a,b= map(int, input().split())
for k in range(a,b+1):
bus[k] += 1
p = int(input())
res = []
for j in range(p):
w = int(input())
res.append(bus[w])
print("#{}".format(i+1),end = " ")
for j in range(len(res)):
print(res[j],end=" ",sep = " ")
print()