STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0


def order(card_sym):
  order = int(card_sym[1])
  return order


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main() STABLE = 'Stable' STABLE 'Stable' UNSTABLE = 'Not stable' UNSTABLE 'Not stable' def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0 main card_num = int(input()) card_num int(input()) int input() input cards = input().split() cards input().split() ().split () input split bubble_sorted = bubble_sort(cards, card_num) bubble_sorted bubble_sort(cards, card_num) bubble_sort cards card_num select_sorted = select_sort(cards, card_num) select_sorted select_sort(cards, card_num) select_sort cards card_num stability = True stability True for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
   i c enumerate(select_sorted) enumerate select_sorted if c != bubble_sorted[i]:
      stability = False
      break
   c != bubble_sorted[i] c bubble_sorted[i] bubble_sorted i stability = False stability False break stability = STABLE if stability else UNSTABLE stability STABLE if stability else UNSTABLE stability STABLE UNSTABLE print(' '.join(bubble_sorted)) print ' '.join(bubble_sorted) ' '.join ' ' join bubble_sorted print(STABLE) print STABLE print(' '.join(select_sorted)) print ' '.join(select_sorted) ' '.join ' ' join select_sorted print(stability) print stability return 0 0 def order(card_sym):
  order = int(card_sym[1])
  return order order order = int(card_sym[1]) order int(card_sym[1]) int card_sym[1] card_sym 1 return order order card_sym card_sym def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements select_sort elements = list(elements) elements list(elements) list elements for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

   i range(0, element_num - 1) range 0 element_num - 1 element_num 1 min_val = order(elements[i + 1]) min_val order(elements[i + 1]) order elements[i + 1] elements i + 1 i 1 min_index = i + 1 min_index i + 1 i 1 for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
     j range(i + 1, element_num) range i + 1 i 1 element_num if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
     order(elements[j]) < min_val order(elements[j]) order elements[j] elements j min_val min_val = order(elements[j]) min_val order(elements[j]) order elements[j] elements j min_index = j min_index j if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

   order(elements[i]) > order(elements[min_index]) order(elements[i]) order elements[i] elements i order(elements[min_index]) order elements[min_index] elements min_index elements[i], elements[min_index] = elements[min_index], elements[i] elements[i] elements i elements[min_index] elements min_index elements[min_index] elements min_index elements[i] elements i return elements elements elements elements element_num element_num def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements bubble_sort elements = list(elements) elements list(elements) list elements for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

   i range(1, element_num) range 1 element_num for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

   j reversed(range(i, element_num)) reversed range(i, element_num) range i element_num if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

   order(elements[j - 1]) > order(elements[j]) order(elements[j - 1]) order elements[j - 1] elements j - 1 j 1 order(elements[j]) order elements[j] elements j elements[j - 1], elements[j] = elements[j], elements[j - 1] elements[j - 1] elements j - 1 j 1 elements[j] elements j elements[j] elements j elements[j - 1] elements j - 1 j 1 return elements elements elements elements element_num element_num if __name__ == '__main__':
  main() __name__ == '__main__' __name__ '__main__' main() main def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0 def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0 main def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements bubble_sort def order(card_sym):
  order = int(card_sym[1])
  return order def order(card_sym):
  order = int(card_sym[1])
  return order order def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements select_sort UNSTABLE = 'Not stable' 'Not stable' UNSTABLE STABLE = 'Stable' 'Stable' STABLE
STABLE = 'Stable'
UNSTABLE = 'Not stable'


def main():
  card_num = int(input())
  cards = input().split()

  bubble_sorted = bubble_sort(cards, card_num)
  select_sorted = select_sort(cards, card_num)

  stability = True
  for i, c in enumerate(select_sorted):
    if c != bubble_sorted[i]:
      stability = False
      break
  stability = STABLE if stability else UNSTABLE

  print(' '.join(bubble_sorted))
  print(STABLE)

  print(' '.join(select_sorted))
  print(stability)

  return 0


def order(card_sym):
  order = int(card_sym[1])
  return order


def select_sort(elements, element_num):
  elements = list(elements)

  for i in range(0, element_num - 1):
    min_val = order(elements[i + 1])
    min_index = i + 1
    for j in range(i + 1, element_num):
      if order(elements[j]) < min_val:
        min_val = order(elements[j])
        min_index = j
    if order(elements[i]) > order(elements[min_index]):
      elements[i], elements[min_index] = elements[min_index], elements[i]

  return elements


def bubble_sort(elements, element_num):
  elements = list(elements)

  for i in range(1, element_num):
    for j in reversed(range(i, element_num)):
      if order(elements[j - 1]) > order(elements[j]):
        elements[j - 1], elements[j] = elements[j], elements[j - 1]

  return elements


if __name__ == '__main__':
  main()