n = int(eval(input()))+1

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

cnt = []

for i in range(100005):

    cnt.append(0)

sum = 0



for i in a:

    cnt[i] += 1

for i in range(100005):

    sum += i * cnt[i]



q = int(eval(input()))



for i in range(q):

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

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

    cnt[c] += cnt[b]

    cnt[b] = 0

    print(sum)









n = int(eval(input()))+1

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

cnt = []

for i in range(100005):

    cnt.append(0)

sum = 0



# a.count(i)を使うとTLE

# count()がO(N)のためfor内で使用するとO(N2)になる？

for i in a:

    cnt[i] += 1

for i in range(100005):

    sum += i * cnt[i]



q = int(eval(input()))

ans = []

for i in range(q):

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

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

    cnt[c] += cnt[b]

    cnt[b] = 0

    ans.append(sum)



for i in ans:

    print(i)
n = int(eval(input())) + 1
a = list(map(int, input().split()))
cnt = []
for i in range(100005):
    cnt.append(0)
sum = 0
for i in a:
    cnt[i] += 1
for i in range(100005):
    sum += i * cnt[i]
q = int(eval(input()))
for i in range(q):
    b, c = list(map(int, input().split()))
    sum += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(sum)

n = int(eval(input())) + 1
a = list(map(int, input().split()))
cnt = []
for i in range(100005):
    cnt.append(0)
sum = 0
# a.count(i)を使うとTLE
# count()がO(N)のためfor内で使用するとO(N2)になる？
for i in a:
    cnt[i] += 1
for i in range(100005):
    sum += i * cnt[i]
q = int(eval(input()))
ans = []
for i in range(q):
    b, c = list(map(int, input().split()))
    sum += (c - b) * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    ans.append(sum)
for i in ans:
    print(i)

+# a.count(i)を使うとTLE +# count()がO(N)のためfor内で使用するとO(N2)になる？ +ans = [] -    print(sum) +    ans.append(sum) +for i in ans: +    print(i)