import numpy as np
N = int(input())
A=list(map(int,input().split()))
A=np.array(A)
Q=int(input())
BC = [map(int, input().split()) for _ in range(Q)]
B, C = [list(i) for i in zip(*BC)]
for i in range(Q):
	for j in range(len(A)):
		if A[j]==B[i]:
			A[j]=C[i]   
	print(np.sum(A))