N = int(input())
A = list(input().split())
A_copy = A[:]

def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1

def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp

bubble_sort(N, A)
selection_sort(N,A_copy)
print(' '.join(map(str, A)))
print('Stable')
print(' '.join(map(str, A_copy)))
if A == A_copy:
  print('Stable')
else:
  print('Not stable')
 N = int(input()) N int(input()) int input() input A = list(input().split()) A list(input().split()) list input().split() ().split () input split A_copy = A[:] A_copy A[:] A : def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1 bubble_sort flag = 1 flag 1 sorted_index = 0 sorted_index 0 while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1 flag flag = 0 flag 0 for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
     i range(N-1, sorted_index, -1) range N-1 N 1 sorted_index -1 if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
     A[i][1] < A[i-1][1] A[i][1] [i] A i 1 A[i-1][1] [i-1] A i-1 i 1 1 temp = A[i] temp A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = temp A[i-1] A i-1 i 1 temp flag = 1 flag 1 sorted_index += 1 sorted_index 1 N N A A def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp selection_sort for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp i range(0, N-1) range 0 N-1 N 1 minj = i minj i for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
     j range(i+1, N) range i+1 i 1 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 i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp i is not minj i minj temp = A[i] temp A[i] A i A[i] = A[minj] A[i] A i A[minj] A minj A[minj] = temp A[minj] A minj temp N N A A bubble_sort(N, A) bubble_sort N A selection_sort(N,A_copy) selection_sort N A_copy print(' '.join(map(str, A))) print ' '.join(map(str, A)) ' '.join ' ' join map(str, A) map str A print('Stable') print 'Stable' print(' '.join(map(str, A_copy))) print ' '.join(map(str, A_copy)) ' '.join ' ' join map(str, A_copy) map str A_copy if A == A_copy:
  print('Stable')
else:
  print('Not stable') A == A_copy A A_copy print('Stable') print 'Stable' print('Not stable') print 'Not stable' A_copy = A[:] A[:] A_copy def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1 def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1 bubble_sort def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp selection_sort A = list(input().split()) list(input().split()) A N = int(input()) int(input()) N
N = int(input())
A = list(input().split())
A_copy = A[:]

def bubble_sort(N, A):
  flag = 1
  sorted_index = 0
  while flag:
    flag = 0
    for i in range(N-1, sorted_index, -1):  # N-1からソート済みのインデックス番号まで降順
      if A[i][1] < A[i-1][1]:
        temp = A[i]
        A[i] = A[i-1]
        A[i-1] = temp
        flag = 1
    sorted_index += 1

def selection_sort(N, A):
  for i in range(0, N-1):
    minj = i
    for j in range(i+1, N):
      if A[j][1] < A[minj][1]:
        minj = j
    if i is not minj:
      temp = A[i]
      A[i] = A[minj]
      A[minj] = temp

bubble_sort(N, A)
selection_sort(N,A_copy)
print(' '.join(map(str, A)))
print('Stable')
print(' '.join(map(str, A_copy)))
if A == A_copy:
  print('Stable')
else:
  print('Not stable')

