N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [tuple(map(int, input().split())) for _ in range(Q)]

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