# Aizu Problem ALDS_1_2_C: Stable Sort
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))


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

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

def is_stable(A, B):
    for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
    return True
        
N = int(input())
A = list(input().split())
A_bubble = bubble_sort(A[:])
printA(A_bubble)
print("Stable" if is_stable(A, A_bubble) else "Not stable")
A_select = selection_sort(A[:])
printA(A_select)
print("Stable" if is_stable(A, A_select) else "Not stable") import sys, math, os sys math os PYDEV = os.environ.get('PYDEV') PYDEV os.environ.get('PYDEV') os.environ.get os.environ os environ get 'PYDEV' if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt") PYDEV=="True" PYDEV "True" sys.stdin = open("sample-input2.txt", "rt") sys.stdin sys stdin open("sample-input2.txt", "rt") open "sample-input2.txt" "rt" def printA(A):
    print(' '.join([str(a) for a in A])) printA str(a) for a in A for a in A a A for a in A str(a) str a print(' '.join([str(a) for a in A])) print ' '.join([str(a) for a in A]) ' '.join ' ' join [str(a) for a in A] A A def bubble_sort(A):
    for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
    return A bubble_sort for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
     i range(len(A) - 1) range len(A) - 1 len(A) len A 1 for j in range(len(A) - 1, i, -1):
            if A[j][1] < 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 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 selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][1] < A[mini][1]:
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A selection_sort for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][1] < A[mini][1]:
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
     i range(len(A)) range len(A) len A mini = i mini i for j in range(i, len(A)):
            if A[j][1] < A[mini][1]:
                mini = j
         j range(i, len(A)) range i len(A) len A if A[j][1] < A[mini][1]:
                mini = j
         A[j][1] < A[mini][1] A[j][1] [j] A j 1 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 A A def is_stable(A, B):
    for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
    return True
         is_stable for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
     val range(1, 10) range 1 10 v = str(val) v str(val) str val if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
     [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v] [a[0] for a in A if a[1] == v] [b[0] for b in B if b[1] == v] 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 A_bubble = bubble_sort(A[:]) A_bubble bubble_sort(A[:]) bubble_sort A[:] A : printA(A_bubble) printA A_bubble print("Stable" if is_stable(A, A_bubble) else "Not stable") print "Stable" if is_stable(A, A_bubble) else "Not stable" is_stable(A, A_bubble) is_stable A A_bubble "Stable" "Not stable" A_select = selection_sort(A[:]) A_select selection_sort(A[:]) selection_sort A[:] A : printA(A_select) printA A_select print("Stable" if is_stable(A, A_select) else "Not stable") print "Stable" if is_stable(A, A_select) else "Not stable" is_stable(A, A_select) is_stable A A_select "Stable" "Not stable" def printA(A):
    print(' '.join([str(a) for a in A])) def printA(A):
    print(' '.join([str(a) for a in A])) printA def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][1] < A[mini][1]:
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A def selection_sort(A):
    for i in range(len(A)):
        mini = i
        for j in range(i, len(A)):
            if A[j][1] < A[mini][1]:
                mini = j
        if mini != i:
            A[i], A[mini] = A[mini], A[i]
    return A selection_sort A = list(input().split()) list(input().split()) A A_bubble = bubble_sort(A[:]) bubble_sort(A[:]) A_bubble def bubble_sort(A):
    for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
    return A def bubble_sort(A):
    for i in range(len(A) - 1):
        for j in range(len(A) - 1, i, -1):
            if A[j][1] < A[j - 1][1]:
                A[j], A[j - 1] = A[j - 1], A[j]
    return A bubble_sort N = int(input()) int(input()) N A_select = selection_sort(A[:]) selection_sort(A[:]) A_select PYDEV = os.environ.get('PYDEV') os.environ.get('PYDEV') PYDEV def is_stable(A, B):
    for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
    return True
         def is_stable(A, B):
    for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
    return True
         is_stable
# Aizu Problem ALDS_1_2_C: Stable Sort
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input2.txt", "rt")


def printA(A):
    print(' '.join([str(a) for a in A]))


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

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

def is_stable(A, B):
    for val in range(1, 10):
        v = str(val)
        if [a[0] for a in A if a[1] == v] != [b[0] for b in B if b[1] == v]:
            return False
    return True
        
N = int(input())
A = list(input().split())
A_bubble = bubble_sort(A[:])
printA(A_bubble)
print("Stable" if is_stable(A, A_bubble) else "Not stable")
A_select = selection_sort(A[:])
printA(A_select)
print("Stable" if is_stable(A, A_select) else "Not stable")