import collections



n = int(eval(input()))

a = list(map(int, input().split()))

q = int(eval(input()))



d = collections.Counter(a)

ans = sum(a)



for i in range(q):

    b, c = list(map(int, input().split()))

    num = (c-b)*d[b]

    ans += num

    print(ans)

    d[c] += d[b]

    d[b] = 0
import collections



n = int(eval(input()))

a = list(map(int, input().split()))

q = int(eval(input()))



bc = []



for i in range(q):

    bci = list(map(int, input().split()))

    bc.append(bci)



d = collections.Counter(a)

ans = sum(a)



for i in range(q):

    b, c = bc[i]

    num = (c-b)*d[b]

    ans += num

    print(ans)

    d[c] += d[b]

    d[b] = 0
import collections

n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
    b, c = list(map(int, input().split()))
    num = (c - b) * d[b]
    ans += num
    print(ans)
    d[c] += d[b]
    d[b] = 0

import collections

n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = []
for i in range(q):
    bci = list(map(int, input().split()))
    bc.append(bci)
d = collections.Counter(a)
ans = sum(a)
for i in range(q):
    b, c = bc[i]
    num = (c - b) * d[b]
    ans += num
    print(ans)
    d[c] += d[b]
    d[b] = 0

+bc = [] +for i in range(q): +    bci = list(map(int, input().split())) +    bc.append(bci) -    b, c = list(map(int, input().split())) +    b, c = bc[i]