#coding:utf-8
from copy import deepcopy

n = int(input())
A = list(input().split())
B = deepcopy(A)


def BubbleSort(A,N):
    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]


def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])

print(A)
print("Stable")

print(B)
if A == B:
    print("Stable")
else:
    print("Not stable")
 from copy import deepcopy n = int(input()) n int(input()) int input() input A = list(input().split()) A list(input().split()) list input().split() ().split () input split B = deepcopy(A) B deepcopy(A) deepcopy A def BubbleSort(A,N):
    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] BubbleSort 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 A A N N def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                 SelectionSort for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                 i range(N) range N minj = i minj i for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
         j range(i,N) range i N if A[j][1] < A[minj][1]:
                minj = j
         A[j][1] < A[minj][1] A[j][1] [j] A j 1 A[minj][1] [minj] A minj 1 minj = j minj j A[i], A[minj] = A[minj], A[i] A[i] A i A[minj] A minj A[minj] A minj A[i] A i A A N N BubbleSort(A,n) BubbleSort A n SelectionSort(B,n) SelectionSort B n data for data in A for data in A data A for data in A data A = " ".join([data for data in A]) A " ".join([data for data in A]) " ".join " " join [data for data in A] data for data in B for data in B data B for data in B data B = " ".join([data for data in B]) B " ".join([data for data in B]) " ".join " " join [data for data in B] print(A) print A print("Stable") print "Stable" print(B) print B if A == B:
    print("Stable")
else:
    print("Not stable") A == B A B print("Stable") print "Stable" print("Not stable") print "Not stable" def BubbleSort(A,N):
    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] def BubbleSort(A,N):
    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] BubbleSort B = " ".join([data for data in B]) " ".join([data for data in B]) B A = " ".join([data for data in A]) " ".join([data for data in A]) A def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                 def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                 SelectionSort n = int(input()) int(input()) n A = list(input().split()) list(input().split()) A B = deepcopy(A) deepcopy(A) B
#coding:utf-8
from copy import deepcopy

n = int(input())
A = list(input().split())
B = deepcopy(A)


def BubbleSort(A,N):
    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]


def SelectionSort(A,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j][1] < A[minj][1]:
                minj = j
        A[i], A[minj] = A[minj], A[i]
        
                
BubbleSort(A,n)
SelectionSort(B,n)
A = " ".join([data for data in A])
B = " ".join([data for data in B])

print(A)
print("Stable")

print(B)
if A == B:
    print("Stable")
else:
    print("Not stable")

