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

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

B = bubble(A[:])
print(" ".join(B[:]))
print("Stable")
S = select(A)
print(" ".join(S))
print("Stable" if " ".join(B) == " ".join(S) else "Not stable") 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 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[:] B : print("Stable") print "Stable" S = select(A) S select(A) select A print(" ".join(S)) print " ".join(S) " ".join " " join S print("Stable" if " ".join(B) == " ".join(S) else "Not stable") print "Stable" if " ".join(B) == " ".join(S) else "Not stable" " ".join(B) == " ".join(S) " ".join(B) " ".join " " join B " ".join(S) " ".join " " join S "Stable" "Not stable" 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 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 S = select(A) select(A) S B = bubble(A[:]) bubble(A[:]) 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 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 n = int(input()) int(input()) n
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

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

B = bubble(A[:])
print(" ".join(B[:]))
print("Stable")
S = select(A)
print(" ".join(S))
print("Stable" if " ".join(B) == " ".join(S) else "Not stable")