import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0]*q
c = [0]*q
for i in range(q):
    b[i], c[i] = map(int, input().split())

counter = collections.Counter(a)
s = sum(a[:])
change = []
count = []
for i in range(q):
    s += (c[i]-b[i])*counter[b[i]]
    for j in range(len(change)):
        if b[i] == change[j]:
            s += (c[i]-b[i])*count[j]
    change.append(c[i])
    count.append(counter[b[i]])
    print(s)