from collections import Counter



n = int(eval(input()))

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

q = int(eval(input()))



counter = Counter(a)

sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので



# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）

for _ in range(q):

    before, after = list(map(int, input().split()))



    # 合計を変更します

    sum_res -= before * counter[before]

    sum_res += after * counter[before]



    # 個数を変更します

    counter[after] += counter[before]

    counter[before] = 0



    print(sum_res)
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)]



cou = Counter(a)

s = sum(a)



for b, c in bc:

    s = s + cou[b]*(c-b)

    cou[c] += cou[b]

    cou[b] = 0

    print(s)
from collections import Counter

n = int(eval(input()))
a = list(map(int, input().split()))
q = int(eval(input()))
counter = Counter(a)
sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので
# q回操作します。ループ変数は使わないので_とします（Pythonの慣習）
for _ in range(q):
    before, after = list(map(int, input().split()))
    # 合計を変更します
    sum_res -= before * counter[before]
    sum_res += after * counter[before]
    # 個数を変更します
    counter[after] += counter[before]
    counter[before] = 0
    print(sum_res)

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)]
cou = Counter(a)
s = sum(a)
for b, c in bc:
    s = s + cou[b] * (c - b)
    cou[c] += cou[b]
    cou[b] = 0
    print(s)

-counter = Counter(a) -sum_res = sum(a)  # はじめの合計、名前がsumだとsum関数とかぶってよくないので -# q回操作します。ループ変数は使わないので_とします（Pythonの慣習） -for _ in range(q): -    before, after = list(map(int, input().split())) -    # 合計を変更します -    sum_res -= before * counter[before] -    sum_res += after * counter[before] -    # 個数を変更します -    counter[after] += counter[before] -    counter[before] = 0 -    print(sum_res) +bc = [list(map(int, input().split())) for _ in range(q)] +cou = Counter(a) +s = sum(a) +for b, c in bc: +    s = s + cou[b] * (c - b) +    cou[c] += cou[b] +    cou[b] = 0 +    print(s)