n = int(input())
a = list(map(int, input().split()))
q = int(input())
p = [list(map(int, input().split())) for _ in range(q)]
from collections import Counter
c = Counter(a)
for i in range(q):
    if p[i][0] in c:
        c[p[i][1]] += c[p[i][0]]
        c[p[i][0]] = 0
        print(c)
    ans = 0
    for i in c:
        ans += c[i] * i
    print(ans)