import numpy as np
import sys
N=int(sys.stdin.readline())
A=list(map(int,sys.stdin.readline().split()))
Q=int(sys.stdin.readline())
A=sorted(A)
A=np.array(A)
b=[]
c=[]
for _ in range(Q):
  B,C=map(int,sys.stdin.readline().split())
  b.append(B)
  c.append(C)
for i in range(Q):
  A[A==b[i]]=c[i]
  print(A)
  print(sum(A))
