import numpy as np
n = int(input())
an = np.array(list(map(int, input().split())))
q = int(input())
bici=[[] for i in range(q)]
for i in range(q):
    bici[i] = list(map(int, input().split()))
    an = np.where(an == bici[i][0],bici[i][1],an)
    Ans = np.sum(an)
    print(Ans)