import itertools
N=int(input())
A=list(map(int,input().split()))
A=sorted(A)
Q=int(input())
B=[0]*Q;C=[0]*Q
for i in range(Q):
  B[i],C[i]=map(int,input().split())
#print(A)

S=[[0 for i in range(N)] for j in range(Q+1)]


for i in range(Q):
  for j in range(N):
    S[i][j]=A[j]
    if B[i]==A[j]:
      A[j]=C[i]
S[Q]=A
for i in range(1,Q+1):
  print(sum(S[i]))