n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
s = []
for i in range(100000):
    s.append(a.count(i))
ans = sum(a)

for i in range(q):
    bi,ci = map(int, input().split())
    b.append(bi)
    c.append(ci)
for i in range(q):
    ans += s[b[i]] * (c[i]-b[i])
    s[c[i]] += s[b[i]]
    s[b[i]] = 0
    print(ans)