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={}
for i in range(q):
    s = list(map(int, input().split()))
    plog[(s[0],s[1])]=1
for s in plog:
    a=np.where(a==s[0],s[1],a)
    print(np.sum(a))
