from sys import stdin

readline = stdin.readline



N = int(readline())

A = list(map(int, readline().split()))

Q = int(readline())



t = sum(A)

d = {}

for a in A:

    d.setdefault(a, 0)

    d[a] += 1



for _ in range(Q):

    B, C = list(map(int, readline().split()))

    d.setdefault(B, 0)

    d.setdefault(C, 0)

    t -= B * d[B]

    t += C * d[B]

    d[C] += d[B]

    d[B] = 0

    print(t)

from sys import stdin

readline = stdin.readline



N = int(readline())

A = list(map(int, readline().split()))

Q = int(readline())



t = [0] * (10 ** 5 + 1)

s = sum(A)

for a in A:

    t[a] += 1



for _ in range(Q):

    B, C = list(map(int, readline().split()))

    s -= B * t[B]

    s += C * t[B]

    t[C] += t[B]

    t[B] = 0

    print(s)

from sys import stdin

readline = stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
t = sum(A)
d = {}
for a in A:
    d.setdefault(a, 0)
    d[a] += 1
for _ in range(Q):
    B, C = list(map(int, readline().split()))
    d.setdefault(B, 0)
    d.setdefault(C, 0)
    t -= B * d[B]
    t += C * d[B]
    d[C] += d[B]
    d[B] = 0
    print(t)

from sys import stdin

readline = stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
t = [0] * (10**5 + 1)
s = sum(A)
for a in A:
    t[a] += 1
for _ in range(Q):
    B, C = list(map(int, readline().split()))
    s -= B * t[B]
    s += C * t[B]
    t[C] += t[B]
    t[B] = 0
    print(s)

-t = sum(A) -d = {} +t = [0] * (10**5 + 1) +s = sum(A) -    d.setdefault(a, 0) -    d[a] += 1 +    t[a] += 1 -    d.setdefault(B, 0) -    d.setdefault(C, 0) -    t -= B * d[B] -    t += C * d[B] -    d[C] += d[B] -    d[B] = 0 -    print(t) +    s -= B * t[B] +    s += C * t[B] +    t[C] += t[B] +    t[B] = 0 +    print(s)