import copy
N = int(input())
A = input().split()
B = copy.copy(A)
boo = 1
while boo:
    boo = 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]
            boo = 1
print(*A)
print("Stable")
for i in range(N):
    mi = i
    for j in range(i,N):
        if B[mi][1] > B[j][1]:
            mi = j
    B[i], B[mi] = B[mi], B[i]
if A==B:
    print(*B)
    print("Stable")
else:
    print(*B)
    print("Not stable")
 import copy copy N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split B = copy.copy(A) B copy.copy(A) copy.copy copy copy A boo = 1 boo 1 while boo:
    boo = 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]
            boo = 1 boo boo = 0 boo 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]
            boo = 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]
            boo = 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 boo = 1 boo 1 print(*A) print *A A print("Stable") print "Stable" for i in range(N):
    mi = i
    for j in range(i,N):
        if B[mi][1] > B[j][1]:
            mi = j
    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[mi][1] > B[j][1]:
            mi = j
     j range(i,N) range i N if B[mi][1] > B[j][1]:
            mi = j
     B[mi][1] > B[j][1] B[mi][1] [mi] B mi 1 B[j][1] [j] B j 1 mi = j mi j B[i], B[mi] = B[mi], B[i] B[i] B i B[mi] B mi B[mi] B mi B[i] B i if A==B:
    print(*B)
    print("Stable")
else:
    print(*B)
    print("Not stable") A==B A B print(*B) print *B B print("Stable") print "Stable" print(*B) print *B B print("Not stable") print "Not stable" A = input().split() input().split() A mi = j j mi N = int(input()) int(input()) N B = copy.copy(A) copy.copy(A) B boo = 1 1 boo boo = 1 1 boo boo = 0 0 boo mi = i i mi
import copy
N = int(input())
A = input().split()
B = copy.copy(A)
boo = 1
while boo:
    boo = 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]
            boo = 1
print(*A)
print("Stable")
for i in range(N):
    mi = i
    for j in range(i,N):
        if B[mi][1] > B[j][1]:
            mi = j
    B[i], B[mi] = B[mi], B[i]
if A==B:
    print(*B)
    print("Stable")
else:
    print(*B)
    print("Not stable")

