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

for i in range(q):
    li_bc.append(tuple(map(int, input().split())))

for l in li_bc:
    li_a = [a if a != l[0] else l[1] for a in li_a]
    print(sum(li_a))