n = int(input())
*A, = input().split()
B = A[:]
for i in range(n):
    for j in range(n-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j]
print(*A)
print("Stable")

for i in range(n):
    mj = i
    for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
    B[i], B[mj] = B[mj], 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 A input().split() ().split () input split B = A[:] B A[:] A : for i in range(n):
    for j in range(n-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j] i range(n) range n for j in range(n-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j] j range(n-1, i, -1) range n-1 n 1 i -1 if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j] 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], A[j-1] = A[j-1], A[j] A[j] A j A[j-1] A j-1 j 1 A[j-1] A j-1 j 1 A[j] A j print(*A) print *A A print("Stable") print "Stable" for i in range(n):
    mj = i
    for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
    B[i], B[mj] = B[mj], B[i] i range(n) range n mj = i mj i for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
     j range(i, n) range i n if B[j][1] < B[mj][1]:
            mj = j
     B[j][1] < B[mj][1] B[j][1] [j] B j 1 B[mj][1] [mj] B mj 1 mj = j mj j B[i], B[mj] = B[mj], B[i] B[i] B i B[mj] B mj B[mj] B mj 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" mj = i i mj B = A[:] A[:] B mj = j j mj n = int(input()) int(input()) n
n = int(input())
*A, = input().split()
B = A[:]
for i in range(n):
    for j in range(n-1, i, -1):
        if A[j][1] < A[j-1][1]:
            A[j], A[j-1] = A[j-1], A[j]
print(*A)
print("Stable")

for i in range(n):
    mj = i
    for j in range(i, n):
        if B[j][1] < B[mj][1]:
            mj = j
    B[i], B[mj] = B[mj], B[i]
print(*B)
if A == B:
    print("Stable")
else:
    print("Not stable")