#import numpy as np

from collections import Counter

from time import time



import sys

readline = sys.stdin.buffer.readline





N = int(eval(input()))

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

#A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)



S = sum(A)

C = Counter(A)



Q = int(eval(input()))

#Q = 10 ** 5



ans = []

s = time()

for _ in range(Q):

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

    #b, c = np.random.randint(1, 10 ** 5 + 1, 2)

    #b, c = 2, 5



    count = C[b]

    S = S + (c - b) * count



    C[c] += count

    C[b] = 0

    

    ans.append(S)



print(('\n'.join(map(str, ans))))

#print('time: ', time() - s)
from collections import Counter





N = int(eval(input()))

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

Q = int(eval(input()))



S = sum(A)

C = Counter(A)



ans = []

for _ in range(Q):

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

    count = C[b]

    S += (c - b) * count

    C[b], C[c] = 0, C[c] + count

    ans.append(S)



print(('\n'.join(map(str, ans))))
# import numpy as np
from collections import Counter
from time import time
import sys

readline = sys.stdin.buffer.readline
N = int(eval(input()))
A = list(map(int, input().split()))
# A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5)
S = sum(A)
C = Counter(A)
Q = int(eval(input()))
# Q = 10 ** 5
ans = []
s = time()
for _ in range(Q):
    b, c = list(map(int, input().split()))
    # b, c = np.random.randint(1, 10 ** 5 + 1, 2)
    # b, c = 2, 5
    count = C[b]
    S = S + (c - b) * count
    C[c] += count
    C[b] = 0
    ans.append(S)
print(("\n".join(map(str, ans))))
# print('time: ', time() - s)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
Q = int(eval(input()))
S = sum(A)
C = Counter(A)
ans = []
for _ in range(Q):
    b, c = list(map(int, input().split()))
    count = C[b]
    S += (c - b) * count
    C[b], C[c] = 0, C[c] + count
    ans.append(S)
print(("\n".join(map(str, ans))))

-# import numpy as np -from time import time -import sys -readline = sys.stdin.buffer.readline -# A = np.random.randint(1, 10 ** 5 + 1, 10 ** 5) +Q = int(eval(input())) -Q = int(eval(input())) -# Q = 10 ** 5 -s = time() -    # b, c = np.random.randint(1, 10 ** 5 + 1, 2) -    # b, c = 2, 5 -    S = S + (c - b) * count -    C[c] += count -    C[b] = 0 +    S += (c - b) * count +    C[b], C[c] = 0, C[c] + count -# print('time: ', time() - s)