#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
n = int(input())
a = list(map(int, input().split()))
q = int(input())
req = [list(map(int, input().split())) for _ in range(q)]
count = [0]*100000
sum = 0
ans = [0]*q

for i in range(100000):
    count[i] = a.count(i+1)

for j in a:
    sum += j

for k in range(q):
    diff = req[k][1] - req[k][0]
    diff = diff * count[req[k][0] - 1]
    count[req[k][1] - 1] += count[req[k][0] - 1]
    count[req[k][0] - 1] = 0
    sum += diff
    ans[k] = sum

for l in range(q):
    print(ans[l])
