# coding: utf-8

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

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

b_ans = BubbleSort(A[:], n)
s_ans = SelectionSort(A[:], n)

print(" ".join(b_ans))
print("Stable")
print(" ".join(s_ans))
if b_ans == s_ans:
    print("Stable")
else:
    print("Not stable") def BubbleSort(A, n):
    for i in range(n-1):
        for j in range(n-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 BubbleSort for i in range(n-1):
        for j in range(n-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(n-1) range n-1 n 1 for j in range(n-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(n-1, i, -1) range n-1 n 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 A A n n def SelectionSort(A, n):
    mini = 1
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        A[i], A[mini] = A[mini], A[i]
    return A SelectionSort mini = 1 mini 1 for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        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 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 n n n = int(input()) n int(input()) int input() input A = input().split() A input().split() ().split () input split b_ans = BubbleSort(A[:], n) b_ans BubbleSort(A[:], n) BubbleSort A[:] A : n s_ans = SelectionSort(A[:], n) s_ans SelectionSort(A[:], n) SelectionSort A[:] A : n print(" ".join(b_ans)) print " ".join(b_ans) " ".join " " join b_ans print("Stable") print "Stable" print(" ".join(s_ans)) print " ".join(s_ans) " ".join " " join s_ans if b_ans == s_ans:
    print("Stable")
else:
    print("Not stable") b_ans == s_ans b_ans s_ans print("Stable") print "Stable" print("Not stable") print "Not stable" def SelectionSort(A, n):
    mini = 1
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        A[i], A[mini] = A[mini], A[i]
    return A def SelectionSort(A, n):
    mini = 1
    for i in range(n):
        mini = i
        for j in range(i, n):
            if int(A[j][1]) < int(A[mini][1]):
                mini = j
        A[i], A[mini] = A[mini], A[i]
    return A SelectionSort b_ans = BubbleSort(A[:], n) BubbleSort(A[:], n) b_ans s_ans = SelectionSort(A[:], n) SelectionSort(A[:], n) s_ans A = input().split() input().split() A n = int(input()) int(input()) n def BubbleSort(A, n):
    for i in range(n-1):
        for j in range(n-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 BubbleSort(A, n):
    for i in range(n-1):
        for j in range(n-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 BubbleSort
# coding: utf-8

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

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

b_ans = BubbleSort(A[:], n)
s_ans = SelectionSort(A[:], n)

print(" ".join(b_ans))
print("Stable")
print(" ".join(s_ans))
if b_ans == s_ans:
    print("Stable")
else:
    print("Not stable")