import collections
n = int(input())
a = collections.Counter(list(map(int,input().split())))
q = int(input())
s = []

for i in range(q):
    b,c = map(int,input().split())
    if b in a:
        a[c] = a[b] + a[c]
        del a[b]
    y = [x*a.get(x) for x in a]
    s.append(sum(y))

for k in range(q):
    print(s[k])