n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][c==d]+'table') n=int(input()) n int(input()) int input() input c=input().split() c input().split() ().split () input split d=c[:] d c[:] c : for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i] i range(n-1) range n-1 n 1 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
  j range(0,n-i-1) range 0 n-i-1 n-i n i 1 if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
  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 m=i m i for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
  j range(i,n) range i n if d[m][1]>d[j][1]:m=j
  d[m][1]>d[j][1] d[m][1] [m] d m 1 d[j][1] [j] d j 1 d[i],d[m]=d[m],d[i] d[i] d i d[m] d m d[m] d m d[i] d i print(*c) print *c c print("Stable") print "Stable" print(*d) print *d d print(['Not s','S'][c==d]+'table') print ['Not s','S'][c==d]+'table' ['Not s','S'][c==d] ['Not s','S'] 'Not s' 'S' c==d c d 'table' m=i i m c=input().split() input().split() c n=int(input()) int(input()) n d=c[:] c[:] d
n=int(input())
c=input().split();d=c[:]
for i in range(n-1):
 for j in range(0,n-i-1):
  if c[j][1]>c[j+1][1]:c[j],c[j+1]=c[j+1],c[j]
 m=i
 for j in range(i,n):
  if d[m][1]>d[j][1]:m=j
 d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(['Not s','S'][c==d]+'table')
