from collections import Counter



n = int(eval(input()))

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

q = int(eval(input()))

bc = [list(map(int, input().split())) for _ in range(q)]

suma = sum(a)

counter = Counter(a)

for i in range(q):

    suma -= bc[i][0] * counter[bc[i][0]]

    suma += bc[i][1] * counter[bc[i][0]]

    counter[bc[i][1]] += counter[bc[i][0]]

    counter[bc[i][0]] = 0

    print(suma)

from collections import Counter



n = int(eval(input()))

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

q = int(eval(input()))

bc = [list(map(int, input().split())) for _ in range(q)]

suma = sum(a)

counter = Counter(a)

for b, c in bc:

    suma -= b * counter[b]

    suma += c * counter[b]

    counter[c] += counter[b]

    counter[b] = 0

    print(suma)

from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = [list(map(int, input().split())) for _ in range(q)]
suma = sum(a)
counter = Counter(a)
for i in range(q):
    suma -= bc[i][0] * counter[bc[i][0]]
    suma += bc[i][1] * counter[bc[i][0]]
    counter[bc[i][1]] += counter[bc[i][0]]
    counter[bc[i][0]] = 0
    print(suma)

from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
bc = [list(map(int, input().split())) for _ in range(q)]
suma = sum(a)
counter = Counter(a)
for b, c in bc:
    suma -= b * counter[b]
    suma += c * counter[b]
    counter[c] += counter[b]
    counter[b] = 0
    print(suma)

-for i in range(q): -    suma -= bc[i][0] * counter[bc[i][0]] -    suma += bc[i][1] * counter[bc[i][0]] -    counter[bc[i][1]] += counter[bc[i][0]] -    counter[bc[i][0]] = 0 +for b, c in bc: +    suma -= b * counter[b] +    suma += c * counter[b] +    counter[c] += counter[b] +    counter[b] = 0