n = int(input())
a = [int(i) for i in input().split(' ')]
q = int(input())
j = []
for i in range(q):
    b, c = (int(i) for i in input().split(' '))
    a = [c if i == b else i for i in a]
    j.append(sum(a))

print("\n".join([str(i) for i in j]))