import numpy

n=int(input())
a=list(map(int, input().split()))
q=int(input())

arra = numpy.array(a)

b = []
c = []
for i in range(q):
    x, y = map(int, input().split())
    b.append(x)
    c.append(y)


for j in range(q):
    numpy.place(arra, arra == b[j], c[j])
    print(sum(arra))
