from sys import *



input = stdin.readline

maxn = 10 ** 5 + 5



Sum = [0] * maxn

Cnt = [0] * maxn



n = int(eval(input()))

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

ans = 0

for x in arr:

	ans += x

	Sum[x] += x

	Cnt[x] += 1 

q = int(eval(input()))

for i in range(q):

	x, y = list(map(int, input().split()))

	ans -= Sum[x]

	ans += y * Cnt[x]

	Sum[y] += y * Cnt[x]

	Cnt[y] += Cnt[x]

	Sum[x] = 0

	Cnt[x] = 0

	print(ans)

from sys import *



input = stdin.readline

maxn = 10 ** 5 + 5



Sum = [0] * maxn

Cnt = [0] * maxn



n = int(eval(input()))

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

ans = 0

for x in arr:

	ans += x

	Sum[x] += x

	Cnt[x] += 1 

q = int(eval(input()))

result = []

for i in range(q):

	x, y = list(map(int, input().split()))

	ans -= Sum[x]

	ans += y * Cnt[x]

	Sum[y] += y * Cnt[x]

	Cnt[y] += Cnt[x]

	Sum[x] = 0

	Cnt[x] = 0

	result.append(ans)

print(('\n'.join(map(str, result))))
from sys import *

input = stdin.readline
maxn = 10**5 + 5
Sum = [0] * maxn
Cnt = [0] * maxn
n = int(eval(input()))
arr = list(map(int, input().split()))
ans = 0
for x in arr:
    ans += x
    Sum[x] += x
    Cnt[x] += 1
q = int(eval(input()))
for i in range(q):
    x, y = list(map(int, input().split()))
    ans -= Sum[x]
    ans += y * Cnt[x]
    Sum[y] += y * Cnt[x]
    Cnt[y] += Cnt[x]
    Sum[x] = 0
    Cnt[x] = 0
    print(ans)

from sys import *

input = stdin.readline
maxn = 10**5 + 5
Sum = [0] * maxn
Cnt = [0] * maxn
n = int(eval(input()))
arr = list(map(int, input().split()))
ans = 0
for x in arr:
    ans += x
    Sum[x] += x
    Cnt[x] += 1
q = int(eval(input()))
result = []
for i in range(q):
    x, y = list(map(int, input().split()))
    ans -= Sum[x]
    ans += y * Cnt[x]
    Sum[y] += y * Cnt[x]
    Cnt[y] += Cnt[x]
    Sum[x] = 0
    Cnt[x] = 0
    result.append(ans)
print(("\n".join(map(str, result))))

+result = [] -    print(ans) +    result.append(ans) +print(("\n".join(map(str, result))))