N = int(input().strip())
A = list(map(int, input().strip().split()))
Q = int(input().strip())
grid = []
for i in range(Q):
    array = list(map(int, input().strip().split()))
    grid.append(array)

for i in range (Q):
    for j in range (N):
        if A[j]==grid[i][0]:
            A[j]=int(grid[i][1])

    print(sum(A))
