n = int(input())
a = input().split()
b = a[:]
flag = 1
while flag:
    flag = 0
    for i in range(n-1):
        if a[i][1] > a[i+1][1]:
            a[i], a[i+1] = a[i+1], a[i]
            flag = 1
print(*a)
print("Stable")

for i in range(n-1):
    min_j = i
    for j in range(i,n):
        if b[j][1] < b[min_j][1]:
            min_j = j
    b[i], b[min_j] = b[min_j], b[i]
print(*b)
if a == b:
    print("Stable")
else:
    print("Not stable") n = int(input()) n int(input()) int input() input a = input().split() a input().split() ().split () input split b = a[:] b a[:] a : flag = 1 flag 1 while flag:
    flag = 0
    for i in range(n-1):
        if a[i][1] > a[i+1][1]:
            a[i], a[i+1] = a[i+1], a[i]
            flag = 1 flag flag = 0 flag 0 for i in range(n-1):
        if a[i][1] > a[i+1][1]:
            a[i], a[i+1] = a[i+1], a[i]
            flag = 1 i range(n-1) range n-1 n 1 if a[i][1] > a[i+1][1]:
            a[i], a[i+1] = a[i+1], a[i]
            flag = 1 a[i][1] > a[i+1][1] a[i][1] [i] a i 1 a[i+1][1] [i+1] a i+1 i 1 1 a[i], a[i+1] = a[i+1], a[i] a[i] a i a[i+1] a i+1 i 1 a[i+1] a i+1 i 1 a[i] a i flag = 1 flag 1 print(*a) print *a a print("Stable") print "Stable" for i in range(n-1):
    min_j = i
    for j in range(i,n):
        if b[j][1] < b[min_j][1]:
            min_j = j
    b[i], b[min_j] = b[min_j], b[i] i range(n-1) range n-1 n 1 min_j = i min_j i for j in range(i,n):
        if b[j][1] < b[min_j][1]:
            min_j = j
     j range(i,n) range i n if b[j][1] < b[min_j][1]:
            min_j = j
     b[j][1] < b[min_j][1] b[j][1] [j] b j 1 b[min_j][1] [min_j] b min_j 1 min_j = j min_j j b[i], b[min_j] = b[min_j], b[i] b[i] b i b[min_j] b min_j b[min_j] b min_j b[i] b i print(*b) print *b b if a == b:
    print("Stable")
else:
    print("Not stable") a == b a b print("Stable") print "Stable" print("Not stable") print "Not stable" flag = 0 0 flag n = int(input()) int(input()) n b = a[:] a[:] b flag = 1 1 flag min_j = j j min_j a = input().split() input().split() a flag = 1 1 flag min_j = i i min_j
n = int(input())
a = input().split()
b = a[:]
flag = 1
while flag:
    flag = 0
    for i in range(n-1):
        if a[i][1] > a[i+1][1]:
            a[i], a[i+1] = a[i+1], a[i]
            flag = 1
print(*a)
print("Stable")

for i in range(n-1):
    min_j = i
    for j in range(i,n):
        if b[j][1] < b[min_j][1]:
            min_j = j
    b[i], b[min_j] = b[min_j], b[i]
print(*b)
if a == b:
    print("Stable")
else:
    print("Not stable")