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]
 b=[s[1]for s in d];m=b.index(min(b[i:]),i)
 if b[i]>b[m]:d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(["Not stable","Stable"][c==d]) 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]
 b=[s[1]for s in d];m=b.index(min(b[i:]),i)
 if b[i]>b[m]: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 s[1]for s in d for s in d s d for s in d s[1] s 1 b=[s[1]for s in d] b [s[1]for s in d] m=b.index(min(b[i:]),i) m b.index(min(b[i:]),i) b.index b index min(b[i:]) min b[i:] b i: i i if b[i]>b[m]:d[i],d[m]=d[m],d[i b[i]>b[m] b[i] b i b[m] b m print(*c) print *c c print("Stable") print "Stable" print(*d) print *d d print(["Not stable","Stable"][c==d]) print ["Not stable","Stable"][c==d] ["Not stable","Stable"] "Not stable" "Stable" c==d c d b=[s[1]for s in d] [s[1]for s in d] b d=c[:] c[:] d m=b.index(min(b[i:]),i) b.index(min(b[i:]),i) m n=int(input()) int(input()) n c=input().split() input().split() c
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]
 b=[s[1]for s in d];m=b.index(min(b[i:]),i)
 if b[i]>b[m]:d[i],d[m]=d[m],d[i]
print(*c);print("Stable")
print(*d)
print(["Not stable","Stable"][c==d])
