from collections import Counter

n = int(eval(input()))

a = [int(i) for i in input().split()]

cnt_a = Counter(a)

q = int(eval(input()))

s = [sum(a)] + [0] * q

for i in range(q):

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

    bn = cnt_a[b]

    s[i + 1] = s[i] + (c - b)*bn

    cnt_a[b] = 0

    cnt_a[c] += bn

    print((s[i + 1]))
from collections import Counter

n = int(input())

a = [int(i) for i in input().split()]

cnt_a = Counter(a)

q = int(input())

s = [sum(a)] + [0] * q

for i in range(q):

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

    bn = cnt_a[b]

    s[i + 1] = s[i] + (c - b)*bn

    cnt_a[b] = 0

    cnt_a[c] += bn

print(*s[1:], sep='\n')

from collections import Counter

n = int(eval(input()))
a = [int(i) for i in input().split()]
cnt_a = Counter(a)
q = int(eval(input()))
s = [sum(a)] + [0] * q
for i in range(q):
    b, c = list(map(int, input().split()))
    bn = cnt_a[b]
    s[i + 1] = s[i] + (c - b) * bn
    cnt_a[b] = 0
    cnt_a[c] += bn
    print((s[i + 1]))

from collections import Counter

n = int(input())
a = [int(i) for i in input().split()]
cnt_a = Counter(a)
q = int(input())
s = [sum(a)] + [0] * q
for i in range(q):
    b, c = map(int, input().split())
    bn = cnt_a[b]
    s[i + 1] = s[i] + (c - b) * bn
    cnt_a[b] = 0
    cnt_a[c] += bn
print(*s[1:], sep="\n")

-n = int(eval(input())) +n = int(input()) -q = int(eval(input())) +q = int(input()) -    b, c = list(map(int, input().split())) +    b, c = map(int, input().split()) -    print((s[i + 1])) +print(*s[1:], sep="\n")