n = int(input())
A = list(map(int, input().split()))
q = int(input())
sousa = [list(map(int, input().split())) for _ in range(q)]

for i in range(q):
    A = [sousa[i][1] if j == sousa[i][0] else j for j in A]
    print(sum(A))