N = int(input())
A = [ x for x in input().split(" ")]
orig_A = A[:]

#bubblesort
for i in range(0, 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]

print(*A)
print("Stable")


#selectionsort
for i in range(0, N):
    minj = i
    for j in range(i, N):
        if int(orig_A[j][1]) < int(orig_A[minj][1]):
            minj = j
    orig_A[i], orig_A[minj] = orig_A[minj], orig_A[i]


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

#bubblesort
for i in range(0, 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]

print(*A)
print("Stable")


#selectionsort
for i in range(0, N):
    minj = i
    for j in range(i, N):
        if int(orig_A[j][1]) < int(orig_A[minj][1]):
            minj = j
    orig_A[i], orig_A[minj] = orig_A[minj], orig_A[i]


print(*orig_A)
print("Stable" if A == orig_A else "Not stable")