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

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

for j in range(q):
    a = [c[j] if i == b[j] else i for i in a]
    print(sum(a))
