N = int(input())
lsn = list(map(int,input().split()))
Q = int(input())
ls2 = []
for i in range(Q):
    Bi,Ci = map(int,input().split())
    ls2.append([Bi,Ci])
for l in ls2:
    lsn = [l[1] if i == l[0] else i for i in lsn]
    print(sum(lsn))