#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):
    print(old_sum + a.count(b[i])*(c[i]-b[i]) + change.count(b[i])*(c[i]-b[i]))
    old_sum = old_sum + a.count(b[i])*(c[i]-b[i]) + change.count(b[i])*(c[i]-b[i]) 
    change += [c[i]]*(a.count(b[i])+change.count(b[i]))