N = int(input())
A1 = list(map(str,input().split()))
A2 = A1[:]

def bubbleSort(A, N):
 flag = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
 return A

def selectSort(A, N):
 for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
 return A

def stable(Ab, As, N):
 for i in range(N):
  if Ab[i] != As[i]:
   return False
 return True

bubbleSort(A1, N)
selectSort(A2, N)
print(" ".join(map(str, A1)))
print("Stable")
print(" ".join(map(str, A2)))
if stable(A1, A2, N):
 print("Stable")
else:
 print("Not stable") N = int(input()) N int(input()) int input() input A1 = list(map(str,input().split())) A1 list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split A2 = A1[:] A2 A1[:] A1 : def bubbleSort(A, N):
 flag = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
 return A bubbleSort flag = 0 flag 0 i = 0 i 0 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
  flag == 0 flag 0 flag = 1 flag 1 for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
   j range(N-1, i, -1) range N-1 N 1 i -1 if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
   A[j][1] < A[j-1][1] A[j][1] [j] A j 1 A[j-1][1] [j-1] A j-1 j 1 1 A[j], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j flag = 0 flag 0 i += 1 i 1 return A A A A N N def selectSort(A, N):
 for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
 return A selectSort for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
  i range(N) range N minj = i minj i for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
   j range(i, N) range i N if A[j][1] < A[minj][1]:
    minj = j
   A[j][1] < A[minj][1] A[j][1] [j] A j 1 A[minj][1] [minj] A minj 1 minj = j minj j if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
  A[i][1] != A[minj][1] A[i][1] [i] A i 1 A[minj][1] [minj] A minj 1 A[i], A[minj] = A[minj], A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i return A A A A N N def stable(Ab, As, N):
 for i in range(N):
  if Ab[i] != As[i]:
   return False
 return True stable for i in range(N):
  if Ab[i] != As[i]:
   return False
  i range(N) range N if Ab[i] != As[i]:
   return False
  Ab[i] != As[i] Ab[i] Ab i As[i] As i return False False return True True Ab Ab As As N N bubbleSort(A1, N) bubbleSort A1 N selectSort(A2, N) selectSort A2 N print(" ".join(map(str, A1))) print " ".join(map(str, A1)) " ".join " " join map(str, A1) map str A1 print("Stable") print "Stable" print(" ".join(map(str, A2))) print " ".join(map(str, A2)) " ".join " " join map(str, A2) map str A2 if stable(A1, A2, N):
 print("Stable")
else:
 print("Not stable") stable(A1, A2, N) stable A1 A2 N print("Stable") print "Stable" print("Not stable") print "Not stable" def bubbleSort(A, N):
 flag = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
 return A def bubbleSort(A, N):
 flag = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
 return A bubbleSort N = int(input()) int(input()) N A2 = A1[:] A1[:] A2 A1 = list(map(str,input().split())) list(map(str,input().split())) A1 def selectSort(A, N):
 for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
 return A def selectSort(A, N):
 for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
 return A selectSort def stable(Ab, As, N):
 for i in range(N):
  if Ab[i] != As[i]:
   return False
 return True def stable(Ab, As, N):
 for i in range(N):
  if Ab[i] != As[i]:
   return False
 return True stable
N = int(input())
A1 = list(map(str,input().split()))
A2 = A1[:]

def bubbleSort(A, N):
 flag = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j][1] < A[j-1][1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
  i += 1
 return A

def selectSort(A, N):
 for i in range(N):
  minj = i
  for j in range(i, N):
   if A[j][1] < A[minj][1]:
    minj = j
  if A[i][1] != A[minj][1]:
   A[i], A[minj] = A[minj], A[i]
 return A

def stable(Ab, As, N):
 for i in range(N):
  if Ab[i] != As[i]:
   return False
 return True

bubbleSort(A1, N)
selectSort(A2, N)
print(" ".join(map(str, A1)))
print("Stable")
print(" ".join(map(str, A2)))
if stable(A1, A2, N):
 print("Stable")
else:
 print("Not stable")