def select(S):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
    return S

def bubble(B):
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
    return B

def isStable(inA, out):
    for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
    return "Stable"



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

B = bubble(A[:])
print(" ".join(B))
print(isStable(A, B))
S = select(A[:])
print(" ".join(S))
print(isStable(A, S)) def select(S):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
    return S select for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
     i range(0, n) range 0 n minj = i minj i for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
         j range(i, n) range i n if int(S[j][1]) < int(S[minj][1]):
                minj = j
         int(S[j][1]) < int(S[minj][1]) int(S[j][1]) int S[j][1] [j] S j 1 int(S[minj][1]) int S[minj][1] [minj] S minj 1 minj = j minj j (S[i], S[minj]) = (S[minj], S[i]) (S[i], S[minj]) S[i] S i S[minj] S minj (S[minj], S[i]) S[minj] S minj S[i] S i return S S S S def bubble(B):
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
    return B bubble flag = True flag True while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
     flag flag = False flag False for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
     j reversed(range(1, n)) reversed range(1, n) range 1 n if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
     int(B[j][1]) < int(B[j-1][1]) int(B[j][1]) int B[j][1] [j] B j 1 int(B[j-1][1]) int B[j-1][1] [j-1] B j-1 j 1 1 (B[j-1], B[j]) = (B[j], B[j-1]) (B[j-1], B[j]) B[j-1] B j-1 j 1 B[j] B j (B[j], B[j-1]) B[j] B j B[j-1] B j-1 j 1 flag = True flag True return B B B B def isStable(inA, out):
    for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
    return "Stable" isStable for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
     i range(0, n) range 0 n for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
     j range(i+1, n) range i+1 i 1 n for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
     a range(0, n) range 0 n for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
     b range(a+1, n) range a+1 a 1 n if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
     inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a] inA[i][1] == inA[j][1] and inA[i] == out[b] inA[i][1] == inA[j][1] inA[i][1] [i] inA i 1 inA[j][1] [j] inA j 1 inA[i] == out[b] inA[i] inA i out[b] out b inA[j] == out[a] inA[j] inA j out[a] out a return "Not stable" "Not stable" return "Stable" "Stable" inA inA out out n = int(input()) n int(input()) int input() input A = input().split(' ') A input().split(' ') ().split () input split ' ' B = bubble(A[:]) B bubble(A[:]) bubble A[:] A : print(" ".join(B)) print " ".join(B) " ".join " " join B print(isStable(A, B)) print isStable(A, B) isStable A B S = select(A[:]) S select(A[:]) select A[:] A : print(" ".join(S)) print " ".join(S) " ".join " " join S print(isStable(A, S)) print isStable(A, S) isStable A S def bubble(B):
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
    return B def bubble(B):
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
    return B bubble def select(S):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
    return S def select(S):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
    return S select B = bubble(A[:]) bubble(A[:]) B S = select(A[:]) select(A[:]) S def isStable(inA, out):
    for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
    return "Stable" def isStable(inA, out):
    for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
    return "Stable" isStable n = int(input()) int(input()) n A = input().split(' ') input().split(' ') A
def select(S):
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if int(S[j][1]) < int(S[minj][1]):
                minj = j
        (S[i], S[minj]) = (S[minj], S[i])
    return S

def bubble(B):
    flag = True
    while flag:
        flag = False
        for j in reversed(range(1, n)):
            if int(B[j][1]) < int(B[j-1][1]):
                (B[j-1], B[j]) = (B[j], B[j-1])
                flag = True
    return B

def isStable(inA, out):
    for i in range(0, n):
        for j in range(i+1, n):
            for a in range(0, n):
                for b in range(a+1, n):
                    if inA[i][1] == inA[j][1] and inA[i] == out[b] and inA[j] == out[a]:
                        return "Not stable"
    return "Stable"



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

B = bubble(A[:])
print(" ".join(B))
print(isStable(A, B))
S = select(A[:])
print(" ".join(S))
print(isStable(A, S))