N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for i in range(Q)]
for x in BC:
    for y in range(N):
        if A[y] == x[0]:
            A[y] = x[1]
    print(sum(A))
