from collections import Counter



N = int(eval(input()))

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

sumA = sum(A)



dic = Counter(A)



Q = int(eval(input()))



for _ in range(Q):

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

    if b in list(dic.keys()):

        sumA += ((c-b)*dic[b])



        #変更後の数字は既にいる？

        if c in list(dic.keys()):

            #個数を保持

            #bの個数をcに追加し、bを削除

            dic[c] += dic[b]

            del dic[b]

        else:

            dic[c] = dic[b]

            del dic[b]

        # print("C", C)

        

        

        

        # print(dic)

    # else:

    #     ans = sumA

    print(sumA)
from collections import Counter



N = int(eval(input()))

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



cnt = [0 for _ in range(100005)]

for i in range(N):

    cnt[A[i]] += 1



sumA = sum(A)



# print(sumA)



Q = int(eval(input()))

for _ in range(Q):

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

    

    if cnt[b]:

        sumA += (c-b)*cnt[b]

        cnt[c] += cnt[b]

        cnt[b] = 0

    print(sumA)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
sumA = sum(A)
dic = Counter(A)
Q = int(eval(input()))
for _ in range(Q):
    b, c = list(map(int, input().split()))
    if b in list(dic.keys()):
        sumA += (c - b) * dic[b]
        # 変更後の数字は既にいる？
        if c in list(dic.keys()):
            # 個数を保持
            # bの個数をcに追加し、bを削除
            dic[c] += dic[b]
            del dic[b]
        else:
            dic[c] = dic[b]
            del dic[b]
        # print("C", C)
        # print(dic)
    # else:
    #     ans = sumA
    print(sumA)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
cnt = [0 for _ in range(100005)]
for i in range(N):
    cnt[A[i]] += 1
sumA = sum(A)
# print(sumA)
Q = int(eval(input()))
for _ in range(Q):
    b, c = list(map(int, input().split()))
    if cnt[b]:
        sumA += (c - b) * cnt[b]
        cnt[c] += cnt[b]
        cnt[b] = 0
    print(sumA)

+cnt = [0 for _ in range(100005)] +for i in range(N): +    cnt[A[i]] += 1 -dic = Counter(A) +# print(sumA) -    if b in list(dic.keys()): -        sumA += (c - b) * dic[b] -        # 変更後の数字は既にいる？ -        if c in list(dic.keys()): -            # 個数を保持 -            # bの個数をcに追加し、bを削除 -            dic[c] += dic[b] -            del dic[b] -        else: -            dic[c] = dic[b] -            del dic[b] -        # print("C", C) -        # print(dic) -    # else: -    #     ans = sumA +    if cnt[b]: +        sumA += (c - b) * cnt[b] +        cnt[c] += cnt[b] +        cnt[b] = 0