import numpy as np
N = int(input())
A = np.array(list(map(int,input().split(" "))))
Q = int(input())
B = [list(map(int,input().split(" "))) for i in range(0,Q)]

for i in range(0,Q):
    A[A == B[i][0]] = B[i][1]
    print(np.sum(A))
#print("\n".join(list(map(str,A.tolist()))))