# -*- coding: utf-8 -*-

N = int(raw_input())
A = map(str, raw_input().split())
B = A[:]
for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            A[j], A[j-1] = A[j-1], A[j]
bubble = " ".join(A)
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[minj][1]):
            minj = j
    B[i], B[minj] = B[minj], B[i]
select = " ".join(B)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable" N = int(raw_input()) N int(raw_input()) int raw_input() raw_input A = map(str, raw_input().split()) A map(str, raw_input().split()) map str raw_input().split() ().split () raw_input split B = A[:] B A[:] A : for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(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 int(A[j][1]) < int(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 int(A[j][1]) < int(A[j-1][1]):
            A[j], A[j-1] = A[j-1], A[j] int(A[j][1]) < int(A[j-1][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[j-1][1]) int 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 bubble = " ".join(A) bubble " ".join(A) " ".join " " join A for i in range(N):
    minj = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[minj][1]):
            minj = j
    B[i], B[minj] = B[minj], B[i] i range(N) range N minj = i minj i for j in range(i, N):
        if int(B[j][1]) < int(B[minj][1]):
            minj = j
     j range(i, N) range i N if int(B[j][1]) < int(B[minj][1]):
            minj = j
     int(B[j][1]) < int(B[minj][1]) int(B[j][1]) int B[j][1] [j] B j 1 int(B[minj][1]) int B[minj][1] [minj] B minj 1 minj = j minj j B[i], B[minj] = B[minj], B[i] B[i] B i B[minj] B minj B[minj] B minj B[i] B i select = " ".join(B) select " ".join(B) " ".join " " join B print print print if bubble == select:
    print "Stable"
else:
    print "Not stable" bubble == select bubble select print print select = " ".join(B) " ".join(B) select N = int(raw_input()) int(raw_input()) N minj = j j minj B = A[:] A[:] B bubble = " ".join(A) " ".join(A) bubble A = map(str, raw_input().split()) map(str, raw_input().split()) A minj = i i minj
# -*- coding: utf-8 -*-

N = int(raw_input())
A = map(str, raw_input().split())
B = A[:]
for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            A[j], A[j-1] = A[j-1], A[j]
bubble = " ".join(A)
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[minj][1]):
            minj = j
    B[i], B[minj] = B[minj], B[i]
select = " ".join(B)
print bubble
print "Stable"
print select
if bubble == select:
    print "Stable"
else:
    print "Not stable"