l, r=len, range
N= int(input())
c1= input().split()
c2=c1[:]
for i in r(l(c1)):
    for j in r(i+1, l(c1))[::-1]:
        if c1[j][1]< c1[j-1][1]:
            c1[j], c1[j-1]= c1[j-1], c1[j]

    m= i
    for j in r(i, l(c2)):
        if c2[j][1] < c2[m][1]: m= j
    c2[i], c2[m]= c2[m], c2[i]
print(*c1)
print("Stable")
print(*c2)
print("Stable" if c1==c2 else "Not stable") l, r=len, range l len r range N= int(input()) N int(input()) int input() input c1= input().split() c1 input().split() ().split () input split c2=c1[:] c2 c1[:] c1 : for i in r(l(c1)):
    for j in r(i+1, l(c1))[::-1]:
        if c1[j][1]< c1[j-1][1]:
            c1[j], c1[j-1]= c1[j-1], c1[j]

    m= i
    for j in r(i, l(c2)):
        if c2[j][1] < c2[m][1]: m= j
    c2[i], c2[m]= c2[m], c2[i] i r(l(c1)) r l(c1) l c1 for j in r(i+1, l(c1))[::-1]:
        if c1[j][1]< c1[j-1][1]:
            c1[j], c1[j-1]= c1[j-1], c1[j]

     j r(i+1, l(c1))[::-1] (i+1, l(c1)) r i+1 i 1 l(c1) l c1 ::-1 -1 if c1[j][1]< c1[j-1][1]:
            c1[j], c1[j-1]= c1[j-1], c1[j]

     c1[j][1]< c1[j-1][1] c1[j][1] [j] c1 j 1 c1[j-1][1] [j-1] c1 j-1 j 1 1 c1[j], c1[j-1]= c1[j-1], c1[j] c1[j] c1 j c1[j-1] c1 j-1 j 1 c1[j-1] c1 j-1 j 1 c1[j] c1 j m= i m i for j in r(i, l(c2)):
        if c2[j][1] < c2[m][1]: m= j
     j r(i, l(c2)) r i l(c2) l c2 if c2[j][1] < c2[m][1]: m= j
     c2[j][1] < c2[m][1] c2[j][1] [j] c2 j 1 c2[m][1] [m] c2 m 1 c2[i], c2[m]= c2[m], c2[i] c2[i] c2 i c2[m] c2 m c2[m] c2 m c2[i] c2 i print(*c1) print *c1 c1 print("Stable") print "Stable" print(*c2) print *c2 c2 print("Stable" if c1==c2 else "Not stable") print "Stable" if c1==c2 else "Not stable" c1==c2 c1 c2 "Stable" "Not stable" m= i i m c1= input().split() input().split() c1 c2=c1[:] c1[:] c2 l, r=len, range len l N= int(input()) int(input()) N r=len, range range r
l, r=len, range
N= int(input())
c1= input().split()
c2=c1[:]
for i in r(l(c1)):
    for j in r(i+1, l(c1))[::-1]:
        if c1[j][1]< c1[j-1][1]:
            c1[j], c1[j-1]= c1[j-1], c1[j]

    m= i
    for j in r(i, l(c2)):
        if c2[j][1] < c2[m][1]: m= j
    c2[i], c2[m]= c2[m], c2[i]
print(*c1)
print("Stable")
print(*c2)
print("Stable" if c1==c2 else "Not stable")