import numpy as np

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

for b,c in BC:
    A[A == b] = c
    print(np.sum(A))
