#coding: UTF-8

import copy
class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")

n = int(input())
r = list(map(str,input().split()))
c = Algo.createIntList(r, n)
br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n)
ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n)
Algo.printList(br, n)
print("Stable")
Algo.printList(ir, n)
if br == ir:
  print("Stable")
else:
  print("Not stable") import copy copy class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") Algo def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

   bubbleSort flag = 1 flag 1 while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
     flag flag = 0 flag 0 for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
     j range(n-1, 0, -1) range n-1 n 1 0 -1 if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
     c[j] < c[j-1] c[j] c j c[j-1] c j-1 j 1 c[j], c[j-1] = c[j-1], c[j] c[j] c j c[j-1] c j-1 j 1 c[j-1] c j-1 j 1 c[j] c j r[j], r[j-1] = r[j-1], r[j] r[j] r j r[j-1] r j-1 j 1 r[j-1] r j-1 j 1 r[j] r j flag = 1 flag 1 return r r r r c c n n @staticmethod
   bubbleSort staticmethod bubbleSort def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

   selectionSort for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
     i range(0,n) range 0 n minj = i minj i for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
       j range(i,n) range i n if c[j] < c[minj]:
          minj = j
       c[j] < c[minj] c[j] c j c[minj] c minj minj = j minj j if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
     c[i] != c[minj] c[i] c i c[minj] c minj c[i], c[minj] = c[minj], c[i] c[i] c i c[minj] c minj c[minj] c minj c[i] c i r[i], r[minj] = r[minj], r[i] r[i] r i r[minj] r minj r[minj] r minj r[i] r i return r r r r c c n n def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

   createIntList c = [] c [] for i in range(0,n):
      c.append(r[i][1])
     i range(0,n) range 0 n c.append(r[i][1]) c.append c append r[i][1] [i] r i 1 return c c r r n n def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") printList for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") i range(0,n) range 0 n if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") i == n-1 i n-1 n 1 print(r[i]) print r[i] r i print(r[i], " ", sep="", end="") print r[i] r i " " sep="" sep "" end="" end "" r r n n n = int(input()) n int(input()) int input() input r = list(map(str,input().split())) r list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split c = Algo.createIntList(r, n) c Algo.createIntList(r, n) Algo.createIntList Algo createIntList r n br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n) br Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n) Algo.bubbleSort Algo bubbleSort copy.deepcopy(r) copy.deepcopy copy deepcopy r copy.deepcopy(c) copy.deepcopy copy deepcopy c n ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n) ir Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n) Algo.selectionSort Algo selectionSort copy.deepcopy(r) copy.deepcopy copy deepcopy r copy.deepcopy(c) copy.deepcopy copy deepcopy c n Algo.printList(br, n) Algo.printList Algo printList br n print("Stable") print "Stable" Algo.printList(ir, n) Algo.printList Algo printList ir n if br == ir:
  print("Stable")
else:
  print("Not stable") br == ir br ir print("Stable") print "Stable" print("Not stable") print "Not stable" r = list(map(str,input().split())) list(map(str,input().split())) r c = Algo.createIntList(r, n) Algo.createIntList(r, n) c ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n) Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n) ir class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="") Algo n = int(input()) int(input()) n br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n) Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n) br
#coding: UTF-8

import copy
class Algo:
  @staticmethod
  def bubbleSort(r, c, n):
    flag = 1
    while flag:
      flag = 0
      for j in range(n-1, 0, -1):
        if c[j] < c[j-1]:
          c[j], c[j-1] = c[j-1], c[j]
          r[j], r[j-1] = r[j-1], r[j]
          flag = 1
    return r

  def selectionSort(r, c, n):
    for i in range(0,n):
      minj = i
      for j in range(i,n):
        if c[j] < c[minj]:
          minj = j
      if c[i] != c[minj]:
        c[i], c[minj] = c[minj], c[i]
        r[i], r[minj] = r[minj], r[i]
    return r

  def createIntList(r, n):
    c = []
    for i in range(0,n):
      c.append(r[i][1])
    return c

  def printList(r, n):
    for i in range(0,n):
      if i == n-1:
        print(r[i])
      else:
        print(r[i], " ", sep="", end="")

n = int(input())
r = list(map(str,input().split()))
c = Algo.createIntList(r, n)
br = Algo.bubbleSort(copy.deepcopy(r), copy.deepcopy(c), n)
ir = Algo.selectionSort(copy.deepcopy(r), copy.deepcopy(c), n)
Algo.printList(br, n)
print("Stable")
Algo.printList(ir, n)
if br == ir:
  print("Stable")
else:
  print("Not stable")