from copy import deepcopy as copy
n=int(input())
A=input().split()
C=copy(A)
for i in range(n):
  for j in range(n-1,i,-1):
    if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable')
C=copy(A)
for i in range(n):
  minj = i
  for j in range(i,n):
    if C[j][1] < C[minj][1]:
      minj = j
  k=C[i]
  C[i]=C[minj]
  C[minj]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable') from copy import deepcopy as copy n=int(input()) n int(input()) int input() input A=input().split() A input().split() ().split () input split C=copy(A) C copy(A) copy A for i in range(n):
  for j in range(n-1,i,-1):
    if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k i range(n) range n for j in range(n-1,i,-1):
    if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k j range(n-1,i,-1) range n-1 n 1 i -1 if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k C[j][1] < C[j-1][1] C[j][1] [j] C j 1 C[j-1][1] [j-1] C j-1 j 1 1 k=C[j] k C[j] C j C[j]=C[j-1] C[j] C j C[j-1] C j-1 j 1 C[j-1]=k C[j-1] C j-1 j 1 k print(*C) print *C C for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable') i range(n-1) range n-1 n 1 if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]) C[i][1]==C[i+1][1] C[i][1] [i] C i 1 C[i+1][1] [i+1] C i+1 i 1 1 A.index(C[i])>A.index(C[i+1]) A.index(C[i]) A.index A index C[i] C i A.index(C[i+1]) A.index A index C[i+1] C i+1 i 1 print('Not stable') print 'Not stable' break C=copy(A) C copy(A) copy A for i in range(n):
  minj = i
  for j in range(i,n):
    if C[j][1] < C[minj][1]:
      minj = j
  k=C[i]
  C[i]=C[minj]
  C[minj]=k i range(n) range n minj = i minj i for j in range(i,n):
    if C[j][1] < C[minj][1]:
      minj = j
   j range(i,n) range i n if C[j][1] < C[minj][1]:
      minj = j
   C[j][1] < C[minj][1] C[j][1] [j] C j 1 C[minj][1] [minj] C minj 1 minj = j minj j k=C[i] k C[i] C i C[i]=C[minj] C[i] C i C[minj] C minj C[minj]=k C[minj] C minj k print(*C) print *C C for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable') i range(n-1) range n-1 n 1 if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]) C[i][1]==C[i+1][1] C[i][1] [i] C i 1 C[i+1][1] [i+1] C i+1 i 1 1 A.index(C[i])>A.index(C[i+1]) A.index(C[i]) A.index A index C[i] C i A.index(C[i+1]) A.index A index C[i+1] C i+1 i 1 print('Not stable') print 'Not stable' break n=int(input()) int(input()) n A=input().split() input().split() A C=copy(A) copy(A) C minj = j j minj minj = i i minj C=copy(A) copy(A) C k=C[i] C[i] k k=C[j] C[j] k
from copy import deepcopy as copy
n=int(input())
A=input().split()
C=copy(A)
for i in range(n):
  for j in range(n-1,i,-1):
    if C[j][1] < C[j-1][1]:
      k=C[j]
      C[j]=C[j-1]
      C[j-1]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable')
C=copy(A)
for i in range(n):
  minj = i
  for j in range(i,n):
    if C[j][1] < C[minj][1]:
      minj = j
  k=C[i]
  C[i]=C[minj]
  C[minj]=k
print(*C)
for i in range(n-1):
  if C[i][1]==C[i+1][1] and A.index(C[i])>A.index(C[i+1]):
    print('Not stable')
    break
else:print('Stable')
