from copy import copy


def bubble_sort(org_A):
    A = copy(org_A)
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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(org_A):
    A = copy(org_A)
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A

n = int(input())
A = input().split()
B = bubble_sort(A)
C = selection_sort(A)
print(' '.join(B))
print('Stable')
print(' '.join(C))
if B == C:
    print('Stable')
else:
    print('Not stable')
 from copy import copy def bubble_sort(org_A):
    A = copy(org_A)
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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 A = copy(org_A) A copy(org_A) copy org_A for i in range(len(A)):
        for j in range(len(A) - 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(len(A)) range len(A) len A for j in range(len(A) - 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(len(A) - 1, i, -1) range len(A) - 1 len(A) len A 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 return A A org_A org_A def selection_sort(org_A):
    A = copy(org_A)
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A selection_sort A = copy(org_A) A copy(org_A) copy org_A n = len(A) n len(A) len A for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
     i range(n) range n mini = i mini i for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
         j range(i, n) range i n if int(A[j][1]) < int(A[mini][1]):
                mini = j
         int(A[j][1]) < int(A[mini][1]) int(A[j][1]) int A[j][1] [j] A j 1 int(A[mini][1]) int A[mini][1] [mini] A mini 1 mini = j mini j if mini != i:
            A[i], A[mini] = A[mini], A[i]
     mini != i mini i A[i], A[mini] = A[mini], A[i] A[i] A i A[mini] A mini A[mini] A mini A[i] A i return A A org_A org_A n = int(input()) n int(input()) int input() input A = input().split() A input().split() ().split () input split B = bubble_sort(A) B bubble_sort(A) bubble_sort A C = selection_sort(A) C selection_sort(A) selection_sort A print(' '.join(B)) print ' '.join(B) ' '.join ' ' join B print('Stable') print 'Stable' print(' '.join(C)) print ' '.join(C) ' '.join ' ' join C if B == C:
    print('Stable')
else:
    print('Not stable') B == C B C print('Stable') print 'Stable' print('Not stable') print 'Not stable' B = bubble_sort(A) bubble_sort(A) B C = selection_sort(A) selection_sort(A) C def bubble_sort(org_A):
    A = copy(org_A)
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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(org_A):
    A = copy(org_A)
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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 def selection_sort(org_A):
    A = copy(org_A)
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A def selection_sort(org_A):
    A = copy(org_A)
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A selection_sort A = input().split() input().split() A n = int(input()) int(input()) n
from copy import copy


def bubble_sort(org_A):
    A = copy(org_A)
    for i in range(len(A)):
        for j in range(len(A) - 1, i, -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(org_A):
    A = copy(org_A)
    n = len(A)
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A

n = int(input())
A = input().split()
B = bubble_sort(A)
C = selection_sort(A)
print(' '.join(B))
print('Stable')
print(' '.join(C))
if B == C:
    print('Stable')
else:
    print('Not stable')

