def bubble_sort(a, n):
  for i in range(0,n):
    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]
  return a

def selection_sort(b, n):
  for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
  return b

if __name__ == '__main__':
  n = int(input())
  a = list(map(str, input().split()))
  b = a[:]
  buble = bubble_sort(a,n)
  select = selection_sort(b,n)
  print(" ".join(map(str, buble)))
  print("Stable")
  print(" ".join(map(str, select)))
  if select == buble:
    print("Stable")
  else:
    print("Not stable") def bubble_sort(a, n):
  for i in range(0,n):
    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]
  return a bubble_sort for i in range(0,n):
    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]
   i range(0,n) range 0 n 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]
   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]
   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 return a a a a n n def selection_sort(b, n):
  for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
  return b selection_sort for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
   i range(0,n) range 0 n minj = i minj i for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
     j range(i, n) range i n if b[j][1] < b[minj][1]:
        minj = j
     b[j][1] < b[minj][1] b[j][1] [j] b j 1 b[minj][1] [minj] b minj 1 minj = j minj j b[i], b[minj] = b[minj], b[i] b[i] b i b[minj] b minj b[minj] b minj b[i] b i return b b b b n n if __name__ == '__main__':
  n = int(input())
  a = list(map(str, input().split()))
  b = a[:]
  buble = bubble_sort(a,n)
  select = selection_sort(b,n)
  print(" ".join(map(str, buble)))
  print("Stable")
  print(" ".join(map(str, select)))
  if select == buble:
    print("Stable")
  else:
    print("Not stable") __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input a = list(map(str, input().split())) a list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split b = a[:] b a[:] a : buble = bubble_sort(a,n) buble bubble_sort(a,n) bubble_sort a n select = selection_sort(b,n) select selection_sort(b,n) selection_sort b n print(" ".join(map(str, buble))) print " ".join(map(str, buble)) " ".join " " join map(str, buble) map str buble print("Stable") print "Stable" print(" ".join(map(str, select))) print " ".join(map(str, select)) " ".join " " join map(str, select) map str select if select == buble:
    print("Stable")
  else:
    print("Not stable") select == buble select buble print("Stable") print "Stable" print("Not stable") print "Not stable" def selection_sort(b, n):
  for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
  return b def selection_sort(b, n):
  for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
  return b selection_sort buble = bubble_sort(a,n) bubble_sort(a,n) buble def bubble_sort(a, n):
  for i in range(0,n):
    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]
  return a def bubble_sort(a, n):
  for i in range(0,n):
    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]
  return a bubble_sort select = selection_sort(b,n) selection_sort(b,n) select a = list(map(str, input().split())) list(map(str, input().split())) a n = int(input()) int(input()) n b = a[:] a[:] b
def bubble_sort(a, n):
  for i in range(0,n):
    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]
  return a

def selection_sort(b, n):
  for i in range(0,n):
    minj = i
    for j in range(i, n):
      if b[j][1] < b[minj][1]:
        minj = j
    b[i], b[minj] = b[minj], b[i]
  return b

if __name__ == '__main__':
  n = int(input())
  a = list(map(str, input().split()))
  b = a[:]
  buble = bubble_sort(a,n)
  select = selection_sort(b,n)
  print(" ".join(map(str, buble)))
  print("Stable")
  print(" ".join(map(str, select)))
  if select == buble:
    print("Stable")
  else:
    print("Not stable")
