import collections
n = int(input())
l = list(map(int, input().split()))
a = int(input())
c = collections.Counter(l)
for i in range(a):
    j,k =  map(int, input().split())
    save = c[j]
    del c[j]
    c[k] += save
    answer = 0
    for q,r in c.items():
        answer += int(q)*int(r)
    print(answer)
