n=int(input())
a = list(map(int, input().split()))
q=int(input())
bc=[]
for i in range(q):
    bc.append(list(map(int, input().split())))


for gyou in range(q):
    a = [bc[gyou][1] if i==bc[gyou][0] else i for i in a]
    print(sum(a))