#d
n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]
b, c = [list(i) for i in zip(*bc)]
old_sum = sum(a)
change = []
for i in range(q):
    z = a.count(b[i])
    y = change.count(b[i])
    dif = c[i]-b[i]
    print(old_sum + (z+y)*dif)
    old_sum = old_sum + (z+y)*dif
    change += [c[i]]*(z+y)