import copy

def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp

def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp

def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
#カード入力
S = [i for i in input().split()]
B = copy.deepcopy(S)

bubble(N, B)
select(N, S)

print(" ".join(B))
print("Stable")
print(" ".join(S))
if st(B, S) == True:
    print("Stable")
else:
    print("Not stable") import copy copy def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp bubble for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp i range(N - 1) range N - 1 N 1 for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp j reversed(range(1, N)) reversed range(1, N) range 1 N if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp A[j - 1][1] > A[j][1] A[j - 1][1] [j - 1] A j - 1 j 1 1 A[j][1] [j] A j 1 tmp = A[j] tmp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = tmp A[j - 1] A j - 1 j 1 tmp N N A A def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp select for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp i range(N) range N min = i min i for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
         j range(i, N) range i N if A[min][1] > A[j][1]:
                min = j
         A[min][1] > A[j][1] A[min][1] [min] A min 1 A[j][1] [j] A j 1 min = j min j tmp = A[i] tmp A[i] A i A[i] = A[min] A[i] A i A[min] A min A[min] = tmp A[min] A min tmp N N A A def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True st for i in range(N):
        if B[i] != S[i]:
            return False
     i range(N) range N if B[i] != S[i]:
            return False
     B[i] != S[i] B[i] B i S[i] S i return False False return True True B B S S N = int(input()) N int(input()) int input() input i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i S = [i for i in input().split()] S [i for i in input().split()] B = copy.deepcopy(S) B copy.deepcopy(S) copy.deepcopy copy deepcopy S bubble(N, B) bubble N B select(N, S) select N S print(" ".join(B)) print " ".join(B) " ".join " " join B print("Stable") print "Stable" print(" ".join(S)) print " ".join(S) " ".join " " join S if st(B, S) == True:
    print("Stable")
else:
    print("Not stable") st(B, S) == True st(B, S) st B S True print("Stable") print "Stable" print("Not stable") print "Not stable" B = copy.deepcopy(S) copy.deepcopy(S) B N = int(input()) int(input()) N def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True st S = [i for i in input().split()] [i for i in input().split()] S def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp bubble def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp select
import copy

def bubble(N, A):
    for i in range(N - 1):
        for j in reversed(range(1, N)):
            if A[j - 1][1] > A[j][1]:
                tmp = A[j]
                A[j] = A[j - 1]
                A[j - 1] = tmp

def select(N, A):
    for i in range(N):
        min = i
        for j in range(i, N):
            if A[min][1] > A[j][1]:
                min = j
        tmp = A[i]
        A[i] = A[min]
        A[min] = tmp

def st(B, S):
    for i in range(N):
        if B[i] != S[i]:
            return False
    return True

N = int(input())
#カード入力
S = [i for i in input().split()]
B = copy.deepcopy(S)

bubble(N, B)
select(N, S)

print(" ".join(B))
print("Stable")
print(" ".join(S))
if st(B, S) == True:
    print("Stable")
else:
    print("Not stable")
