import numpy as np
s = list(map(int, input().split()))
n=s[0]
a = np.array(list(map(int, input().split())))
s = list(map(int, input().split()))
q=s[0]
plog={}
ans=[]
for i in range(q):
    s = list(map(int, input().split()))
    plog[(s[0], s[1])] = 1
    ans.append((s[0], s[1]))
for s in plog:
    a=np.where(a==s[0],s[1],a)
    plog[s] = np.sum(a)
for i in ans:
    print(plog[i])