def bubbleSort(A):
    N = len(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]
    return A


def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A


def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True


N = int(input())
A = list(input().split())

B = bubbleSort(A[:])
print(*B)
if is_stable(A, B):
    print('Stable')
else:
    print('Not stable')

S = selectionSort(A[:])
print(*S)
if is_stable(A, S):
    print('Stable')
else:
    print('Not stable') def bubbleSort(A):
    N = len(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]
    return A bubbleSort N = len(A) N len(A) len 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 return A A A A def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A selectionSort N = len(A) N len(A) len A for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
     i range(N) range N min_i = i min_i i for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
         j range(i, N) range i N if A[j][1] < A[min_i][1]:
                min_i = j
         A[j][1] < A[min_i][1] A[j][1] [j] A j 1 A[min_i][1] [min_i] A min_i 1 min_i = j min_i j if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
     min_i != i min_i i A[i], A[min_i] = A[min_i], A[i] A[i] A i A[min_i] A min_i A[min_i] A min_i A[i] A i return A A A A def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True is_stable for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
     i range(len(B) - 1) range len(B) - 1 len(B) len B 1 if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
     B[i][1] == B[i + 1][1] B[i][1] [i] B i 1 B[i + 1][1] [i + 1] B i + 1 i 1 1 if A.index(B[i]) > A.index(B[i + 1]):
                return False
     A.index(B[i]) > A.index(B[i + 1]) A.index(B[i]) A.index A index B[i] B i A.index(B[i + 1]) A.index A index B[i + 1] B i + 1 i 1 return False False return True True A A B B N = int(input()) N int(input()) int input() input A = list(input().split()) A list(input().split()) list input().split() ().split () input split B = bubbleSort(A[:]) B bubbleSort(A[:]) bubbleSort A[:] A : print(*B) print *B B if is_stable(A, B):
    print('Stable')
else:
    print('Not stable') is_stable(A, B) is_stable A B print('Stable') print 'Stable' print('Not stable') print 'Not stable' S = selectionSort(A[:]) S selectionSort(A[:]) selectionSort A[:] A : print(*S) print *S S if is_stable(A, S):
    print('Stable')
else:
    print('Not stable') is_stable(A, S) is_stable A S print('Stable') print 'Stable' print('Not stable') print 'Not stable' N = int(input()) int(input()) N A = list(input().split()) list(input().split()) A B = bubbleSort(A[:]) bubbleSort(A[:]) B def bubbleSort(A):
    N = len(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]
    return A def bubbleSort(A):
    N = len(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]
    return A bubbleSort def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True is_stable def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A selectionSort S = selectionSort(A[:]) selectionSort(A[:]) S
def bubbleSort(A):
    N = len(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]
    return A


def selectionSort(A):
    N = len(A)
    for i in range(N):
        min_i = i
        for j in range(i, N):
            if A[j][1] < A[min_i][1]:
                min_i = j
        if min_i != i:
            A[i], A[min_i] = A[min_i], A[i]
    return A


def is_stable(A, B):
    for i in range(len(B) - 1):
        if B[i][1] == B[i + 1][1]:
            if A.index(B[i]) > A.index(B[i + 1]):
                return False
    return True


N = int(input())
A = list(input().split())

B = bubbleSort(A[:])
print(*B)
if is_stable(A, B):
    print('Stable')
else:
    print('Not stable')

S = selectionSort(A[:])
print(*S)
if is_stable(A, S):
    print('Stable')
else:
    print('Not stable')