from collections import Counter



import sys



readline = sys.stdin.buffer.readline



N = int(readline())

A = tuple(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

from collections import Counter



read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines



N = int(readline())

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

Q = int(readline())

BC = list(map(int, read().split()))



d = Counter(A)



sub_s = sum(A)



for b, c in zip(BC, 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 = tuple(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
from collections import Counter

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

+import sys -import sys +read = sys.stdin.buffer.read +readlines = sys.stdin.buffer.readlines -BC = [list(map(int, readline().split())) for _ in range(Q)] +BC = list(map(int, read().split())) -for b, c in BC: +for b, c in zip(BC, BC):