"""
input.txt

2
1 2
3
1 100
2 100
100 1000

"""

from sys import stdin
data = stdin.readlines()

n = int(data[0])
a = [int(s) for s in data[1].split()]
q = int(data[2])

i = 1
l = []
while i <= q:
    l.append(int(data[i+2].split()[0]))
    l.append(int(data[i+2].split()[1]))
    i += 1

dic = {}
for s in range(1,10**5):
    tmp = {s: a.count(s)}
    dic.update(tmp)

s = sum(a)
i = 1
while i <= q:
    s = s + (l[2*i-1]-l[2*i-2]) * dic[l[2*i-2]]
    print(s)
    dic[l[2*i-1]] += dic[l[2*i-2]]
    dic[l[2*i-2]] = 0
    i += 1
