n=int(input())
a=[i for i in input().split(" ")]
b=a.copy()
flg=1

while flg:
    flg=0
    for j in range(n-1,0,-1):
        if a[j][1] < a[j-1][1]:
           a[j-1],a[j]=a[j],a[j-1]
           flg=1  

for i in range(n):
    mi=i
    for j in range(i,n):
        if b[j][1] < b[mi][1]:
            mi = j
    if i != mi:
        b[i],b[mi]=b[mi],b[i]

print(" ".join([str(i) for i in a]))
print("Stable")
print(" ".join([str(i) for i in b]))
if a==b:
    print("Stable")
else:
    print("Not stable") n=int(input()) n int(input()) int input() input i for i in input().split(" ") for i in input().split(" ") i input().split(" ") ().split () input split " " for i in input().split(" ") i a=[i for i in input().split(" ")] a [i for i in input().split(" ")] b=a.copy() b a.copy() a.copy a copy flg=1 flg 1 while flg:
    flg=0
    for j in range(n-1,0,-1):
        if a[j][1] < a[j-1][1]:
           a[j-1],a[j]=a[j],a[j-1]
           flg=1   flg flg=0 flg 0 for j in range(n-1,0,-1):
        if a[j][1] < a[j-1][1]:
           a[j-1],a[j]=a[j],a[j-1]
           flg=1   j range(n-1,0,-1) range n-1 n 1 0 -1 if a[j][1] < a[j-1][1]:
           a[j-1],a[j]=a[j],a[j-1]
           flg=1   a[j][1] < a[j-1][1] a[j][1] [j] a j 1 a[j-1][1] [j-1] a j-1 j 1 1 a[j-1],a[j]=a[j],a[j-1] a[j-1] a j-1 j 1 a[j] a j a[j] a j a[j-1] a j-1 j 1 flg=1 flg 1 for i in range(n):
    mi=i
    for j in range(i,n):
        if b[j][1] < b[mi][1]:
            mi = j
    if i != mi:
        b[i],b[mi]=b[mi],b[i] i range(n) range n mi=i mi i for j in range(i,n):
        if b[j][1] < b[mi][1]:
            mi = j
     j range(i,n) range i n if b[j][1] < b[mi][1]:
            mi = j
     b[j][1] < b[mi][1] b[j][1] [j] b j 1 b[mi][1] [mi] b mi 1 mi = j mi j if i != mi:
        b[i],b[mi]=b[mi],b[i] i != mi i mi b[i],b[mi]=b[mi],b[i] b[i] b i b[mi] b mi b[mi] b mi b[i] b i str(i) for i in a for i in a i a for i in a str(i) str i print(" ".join([str(i) for i in a])) print " ".join([str(i) for i in a]) " ".join " " join [str(i) for i in a] print("Stable") print "Stable" str(i) for i in b for i in b i b for i in b str(i) str i print(" ".join([str(i) for i in b])) print " ".join([str(i) for i in b]) " ".join " " join [str(i) for i in b] if a==b:
    print("Stable")
else:
    print("Not stable") a==b a b print("Stable") print "Stable" print("Not stable") print "Not stable" mi=i i mi flg=1 1 flg n=int(input()) int(input()) n a=[i for i in input().split(" ")] [i for i in input().split(" ")] a b=a.copy() a.copy() b flg=0 0 flg flg=1 1 flg mi = j j mi
n=int(input())
a=[i for i in input().split(" ")]
b=a.copy()
flg=1

while flg:
    flg=0
    for j in range(n-1,0,-1):
        if a[j][1] < a[j-1][1]:
           a[j-1],a[j]=a[j],a[j-1]
           flg=1  

for i in range(n):
    mi=i
    for j in range(i,n):
        if b[j][1] < b[mi][1]:
            mi = j
    if i != mi:
        b[i],b[mi]=b[mi],b[i]

print(" ".join([str(i) for i in a]))
print("Stable")
print(" ".join([str(i) for i in b]))
if a==b:
    print("Stable")
else:
    print("Not stable")