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)]



d = Counter(A)



sub_s = sum(A)



for b, c in BC:

    sub_s += d[b] * (c - b)

    d[c] += d[b]

    d[b] = 0



    print(sub_s)

from collections import Counter



import sys



readline = sys.stdin.buffer.readline



N = int(readline())

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



Q = int(readline())

BC = [list(map(int, readline().split())) for _ in range(Q)]



d = Counter(A)



sub_s = sum(A)



for b, c in BC:

    sub_s += d[b] * (c - b)

    d[c] += d[b]

    d[b] = 0



    print(sub_s)

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)]
d = Counter(A)
sub_s = sum(A)
for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0
    print(sub_s)

from collections import Counter
import sys

readline = sys.stdin.buffer.readline
N = int(readline())
A = list(map(int, readline().split()))
Q = int(readline())
BC = [list(map(int, readline().split())) for _ in range(Q)]
d = Counter(A)
sub_s = sum(A)
for b, c in BC:
    sub_s += d[b] * (c - b)
    d[c] += d[b]
    d[b] = 0
    print(sub_s)

+import sys -N = int(eval(input())) -A = list(map(int, input().split())) -Q = int(eval(input())) -BC = [list(map(int, input().split())) for _ in range(Q)] +readline = sys.stdin.buffer.readline +N = int(readline()) +A = list(map(int, readline().split())) +Q = int(readline()) +BC = [list(map(int, readline().split())) for _ in range(Q)]