N = input()
A = raw_input().split()
B = A[:]
for i in xrange(N):
    for j in xrange(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
print ' '.join(B)
print 'Stable'

C = A[:]
for i in xrange(N):
    minj = i
    for j in xrange(i, N):
        if A[j][1] < A[minj][1]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
print ' '.join(A)
s = True
for i in xrange(N):
    for j in xrange(i+1, N):
        if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False
print 'Stable' if s else 'Not stable' N = input() N input() input A = raw_input().split() A raw_input().split() ().split () raw_input split B = A[:] B A[:] A : for i in xrange(N):
    for j in xrange(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j] i xrange(N) xrange N for j in xrange(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j] j xrange(N-1, i, -1) xrange N-1 N 1 i -1 if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j] B[j][1] < B[j-1][1] B[j][1] [j] B j 1 B[j-1][1] [j-1] B j-1 j 1 1 B[j], B[j-1] = B[j-1], B[j] B[j] B j B[j-1] B j-1 j 1 B[j-1] B j-1 j 1 B[j] B j print ' '.join(B) ' '.join ' ' join B print C = A[:] C A[:] A : for i in xrange(N):
    minj = i
    for j in xrange(i, N):
        if A[j][1] < A[minj][1]:
            minj = j
    A[i], A[minj] = A[minj], A[i] i xrange(N) xrange N minj = i minj i for j in xrange(i, N):
        if A[j][1] < A[minj][1]:
            minj = j
     j xrange(i, N) xrange i N if A[j][1] < A[minj][1]:
            minj = j
     A[j][1] < A[minj][1] A[j][1] [j] A j 1 A[minj][1] [minj] A minj 1 minj = j minj j A[i], A[minj] = A[minj], A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i print ' '.join(A) ' '.join ' ' join A s = True s True for i in xrange(N):
    for j in xrange(i+1, N):
        if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False i xrange(N) xrange N for j in xrange(i+1, N):
        if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False j xrange(i+1, N) xrange i+1 i 1 N if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]) A[i][1] == A[j][1] A[i][1] [i] A i 1 A[j][1] [j] A j 1 C.index(A[i]) > C.index(A[j]) C.index(A[i]) C.index C index A[i] A i C.index(A[j]) C.index C index A[j] A j s = False s False print 'Stable' if s else 'Not stable' s 'Stable' 'Not stable' N = input() input() N minj = i i minj C = A[:] A[:] C s = False False s s = True True s A = raw_input().split() raw_input().split() A minj = j j minj B = A[:] A[:] B
N = input()
A = raw_input().split()
B = A[:]
for i in xrange(N):
    for j in xrange(N-1, i, -1):
        if B[j][1] < B[j-1][1]:
            B[j], B[j-1] = B[j-1], B[j]
print ' '.join(B)
print 'Stable'

C = A[:]
for i in xrange(N):
    minj = i
    for j in xrange(i, N):
        if A[j][1] < A[minj][1]:
            minj = j
    A[i], A[minj] = A[minj], A[i]
print ' '.join(A)
s = True
for i in xrange(N):
    for j in xrange(i+1, N):
        if A[i][1] == A[j][1] and C.index(A[i]) > C.index(A[j]):
            s = False
print 'Stable' if s else 'Not stable'