n = int(input())
a = list(map(int,input().split()))
q = int(input())
bcs = []
for i in range(q):
    bcs.append(list(map(int,input().split())))
for bc in bcs:
    a = [bc[1] if i == bc[0] else i for i in a]
    print(sum(a))