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

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

#[真の値 if 条件式 else 偽の値 for 任意の変数名 in 元のリスト]