def print_list(l):
    for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ')

N = int(input())
A = input().split()
B = list(A)
for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            w = A[j]; A[j] = A[j-1]; A[j-1] = w
print_list(A)
print('Stable')

for i in range(N):
    min_j = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[min_j][1]):
            min_j = j
    w = B[i]; B[i] = B[min_j]; B[min_j] = w
print_list(B)
if A == B:
    print('Stable')
else:
    print('Not stable')
 def print_list(l):
    for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ') print_list for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ') i n enumerate(l) enumerate l if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ') i == N - 1 i N - 1 N 1 print(l[i]) print l[i] l i print(l[i], end=' ') print l[i] l i end=' ' end ' ' l l N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split B = list(A) B list(A) list A for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            w = A[j]; A[j] = A[j-1]; A[j-1] = w i range(N) range N for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            w = A[j]; A[j] = A[j-1]; A[j-1] = w j range(N-1, i, -1) range N-1 N 1 i -1 if int(A[j][1]) < int(A[j-1][1]):
            w = A[j]; A[j] = A[j-1]; A[j-1] = w 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 w = A[j] w A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = w A[j-1] A j-1 j 1 w print_list(A) print_list A print('Stable') print 'Stable' for i in range(N):
    min_j = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[min_j][1]):
            min_j = j
    w = B[i]; B[i] = B[min_j]; B[min_j] = w i range(N) range N min_j = i min_j i for j in range(i, N):
        if int(B[j][1]) < int(B[min_j][1]):
            min_j = j
     j range(i, N) range i N if int(B[j][1]) < int(B[min_j][1]):
            min_j = j
     int(B[j][1]) < int(B[min_j][1]) int(B[j][1]) int B[j][1] [j] B j 1 int(B[min_j][1]) int B[min_j][1] [min_j] B min_j 1 min_j = j min_j j w = B[i] w B[i] B i B[i] = B[min_j] B[i] B i B[min_j] B min_j B[min_j] = w B[min_j] B min_j w print_list(B) print_list B if A == B:
    print('Stable')
else:
    print('Not stable') A == B A B print('Stable') print 'Stable' print('Not stable') print 'Not stable' B = list(A) list(A) B def print_list(l):
    for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ') def print_list(l):
    for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ') print_list N = int(input()) int(input()) N min_j = i i min_j w = A[j] A[j] w w = B[i] B[i] w A = input().split() input().split() A min_j = j j min_j
def print_list(l):
    for i, n in enumerate(l):
        if i == N - 1:
            print(l[i])
        else:
            print(l[i], end=' ')

N = int(input())
A = input().split()
B = list(A)
for i in range(N):
    for j in range(N-1, i, -1):
        if int(A[j][1]) < int(A[j-1][1]):
            w = A[j]; A[j] = A[j-1]; A[j-1] = w
print_list(A)
print('Stable')

for i in range(N):
    min_j = i
    for j in range(i, N):
        if int(B[j][1]) < int(B[min_j][1]):
            min_j = j
    w = B[i]; B[i] = B[min_j]; B[min_j] = w
print_list(B)
if A == B:
    print('Stable')
else:
    print('Not stable')

