n = int(input())
a = list(map(int,input().split()))
q = int(input())
bc = [0]*q
ans =[0]*q
for i in range(q) :
    bc[i] = list(map(int,input().split()))

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

for i in range(q) :
    print(ans[i])


