N = int(input())
A = input().split(" ")

def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A

def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A

def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result

A_sorted = bubble_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")

A_sorted = selection_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable") N = int(input()) N int(input()) int input() input A = input().split(" ") A input().split(" ") ().split () input split " " def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A bubble_sort N = len(A) N len(A) len A for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
   i range(N) range N for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
   j range(N - 1, i, -1) range N - 1 N 1 i -1 if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
   int(A[j][1]) < int(A[j - 1][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[j - 1][1]) int A[j - 1][1] [j - 1] A j - 1 j 1 1 A[j - 1], A[j] = A[j], A[j - 1] A[j - 1] A j - 1 j 1 A[j] A j A[j] A j A[j - 1] A j - 1 j 1 return A A A A def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A selection_sort N = len(A) N len(A) len A for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
   i range(N) range N mini = i mini i for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
     j range(i + 1, N) range i + 1 i 1 N if int(A[j][1]) < int(A[mini][1]):
        mini = j
     int(A[j][1]) < int(A[mini][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[mini][1]) int A[mini][1] [mini] A mini 1 mini = j mini j if mini != i:
      A[mini], A[i] = A[i], A[mini]
   mini != i mini i A[mini], A[i] = A[i], A[mini] A[mini] A mini A[i] A i A[i] A i A[mini] A mini return A A A A def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result is_stable map_a = {} map_a {} map_b = {} map_b {} for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

   i range(len(A)) range len(A) len A s_a = A[i][0] s_a A[i][0] [i] A i 0 s_b = B[i][0] s_b B[i][0] [i] B i 0 v_a = A[i][1] v_a A[i][1] [i] A i 1 v_b = B[i][1] v_b B[i][1] [i] B i 1 if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
     v_a in map_a v_a map_a map_a[v_a].append(s_a) [v_a].append [v_a] map_a v_a append s_a map_a[v_a] = [s_a] map_a[v_a] map_a v_a [s_a] s_a if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

   v_b in map_b v_b map_b map_b[v_b].append(s_b) [v_b].append [v_b] map_b v_b append s_b map_b[v_b] = [s_b] map_b[v_b] map_b v_b [s_b] s_b result = True result True for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

   k map_a if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

   len(map_a[k]) > 1 len(map_a[k]) len map_a[k] map_a k 1 result = result and (map_a[k] == map_b[k]) result result and (map_a[k] == map_b[k]) result map_a[k] == map_b[k] map_a[k] map_a k map_b[k] map_b k return result result A A B B A_sorted = bubble_sort(A[:]) A_sorted bubble_sort(A[:]) bubble_sort A[:] A : print(" ".join(A_sorted)) print " ".join(A_sorted) " ".join " " join A_sorted print("Stable") if is_stable(A, A_sorted) else print("Not stable") is_stable(A, A_sorted) is_stable A A_sorted print("Stable") print "Stable" print("Not stable") print "Not stable" A_sorted = selection_sort(A[:]) A_sorted selection_sort(A[:]) selection_sort A[:] A : print(" ".join(A_sorted)) print " ".join(A_sorted) " ".join " " join A_sorted print("Stable") if is_stable(A, A_sorted) else print("Not stable") is_stable(A, A_sorted) is_stable A A_sorted print("Stable") print "Stable" print("Not stable") print "Not stable" N = int(input()) int(input()) N A = input().split(" ") input().split(" ") A def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A bubble_sort def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result is_stable A_sorted = bubble_sort(A[:]) bubble_sort(A[:]) A_sorted A_sorted = selection_sort(A[:]) selection_sort(A[:]) A_sorted def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A selection_sort
N = int(input())
A = input().split(" ")

def bubble_sort(A):
  N = len(A)
  for i in range(N):
    for j in range(N - 1, i, -1):
      if int(A[j][1]) < int(A[j - 1][1]):
        A[j - 1], A[j] = A[j], A[j - 1]
  return A

def selection_sort(A):
  N = len(A)
  for i in range(N):
    mini = i
    for j in range(i + 1, N):
      if int(A[j][1]) < int(A[mini][1]):
        mini = j
    if mini != i:
      A[mini], A[i] = A[i], A[mini]
  return A

def is_stable(A, B):
  map_a = {}
  map_b = {}
  for i in range(len(A)):
    s_a = A[i][0]
    s_b = B[i][0]
    v_a = A[i][1]
    v_b = B[i][1]
    if v_a in map_a:
      map_a[v_a].append(s_a)
    else:
      map_a[v_a] = [s_a]
    if v_b in map_b:
      map_b[v_b].append(s_b)
    else:
      map_b[v_b] = [s_b]

  result = True
  for k in map_a:
    if len(map_a[k]) > 1:
      result = result and (map_a[k] == map_b[k])

  return result

A_sorted = bubble_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")

A_sorted = selection_sort(A[:])
print(" ".join(A_sorted))
print("Stable") if is_stable(A, A_sorted) else print("Not stable")