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

def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A

def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A

BA = bubble_sort(A[:])
SA = selection_sort(A[:])

print(' '.join([str(i) for i in BA]))
print('Stable')
print(' '.join([str(i) for i in SA]))
print('Stable' if SA == BA else 'Not stable') N = int(input()) N int(input()) int input() input A = input().split() A input().split() ().split () input split def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A bubble_sort for i in range(0, N):
        for j in range(i+1, N)[::-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(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
     j range(i+1, N)[::-1] (i+1, N) range i+1 i 1 N ::-1 -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 return A A A A def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A selection_sort for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
     i range(0, N) range 0 N min_i = i min_i i for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
         j range(i+1, N) range i+1 i 1 N if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
         int(A[j][1]) < int(A[min_i][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[min_i][1]) int A[min_i][1] [min_i] A min_i 1 min_i = j min_i j 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 BA = bubble_sort(A[:]) BA bubble_sort(A[:]) bubble_sort A[:] A : SA = selection_sort(A[:]) SA selection_sort(A[:]) selection_sort A[:] A : str(i) for i in BA for i in BA i BA for i in BA str(i) str i print(' '.join([str(i) for i in BA])) print ' '.join([str(i) for i in BA]) ' '.join ' ' join [str(i) for i in BA] print('Stable') print 'Stable' str(i) for i in SA for i in SA i SA for i in SA str(i) str i print(' '.join([str(i) for i in SA])) print ' '.join([str(i) for i in SA]) ' '.join ' ' join [str(i) for i in SA] print('Stable' if SA == BA else 'Not stable') print 'Stable' if SA == BA else 'Not stable' SA == BA SA BA 'Stable' 'Not stable' def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A selection_sort SA = selection_sort(A[:]) selection_sort(A[:]) SA A = input().split() input().split() A def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A bubble_sort N = int(input()) int(input()) N BA = bubble_sort(A[:]) bubble_sort(A[:]) BA
N = int(input())
A = input().split()

def bubble_sort(A):
    for i in range(0, N):
        for j in range(i+1, N)[::-1]:
            if int(A[j][1]) < int(A[j-1][1]):
                A[j], A[j-1] = A[j-1], A[j]
    return A

def selection_sort(A):
    for i in range(0, N):
        min_i = i
        for j in range(i+1, N):
            if int(A[j][1]) < int(A[min_i][1]):
                min_i = j
        A[i], A[min_i] = A[min_i], A[i]
    return A

BA = bubble_sort(A[:])
SA = selection_sort(A[:])

print(' '.join([str(i) for i in BA]))
print('Stable')
print(' '.join([str(i) for i in SA]))
print('Stable' if SA == BA else 'Not stable')