import copy as cp

n = int(input())
A = [str(x) for x in input().split()]
AS = cp.copy(A)


def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X)


BA = bubble(A)



def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS)

MA = minsort()


for k in range(n-1):
    print(str(BA[k])+" ",end = "")
print(str(BA[n-1]))
print("Stable")

for k in range(n-1):
    print(str(MA[k])+" ",end = "")
print(str(MA[n-1]))
if (BA == MA):
    print("Stable")
else :
    print("Not stable")
 import copy as cp copy n = int(input()) n int(input()) int input() input str(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() str(x) str x A = [str(x) for x in input().split()] A [str(x) for x in input().split()] AS = cp.copy(A) AS cp.copy(A) cp.copy cp copy A def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X) bubble for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

     i range(n) range n X[i] = list(X[i]) X[i] X i list(X[i]) list X[i] X i X[i][1] = int(X[i][1]) X[i][1] [i] X i 1 int(X[i][1]) int X[i][1] [i] X i 1 for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

     i range(n) range n for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

     j range(n-1) range n-1 n 1 if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

     X[j+1][1] < X[j][1] X[j+1][1] [j+1] X j+1 j 1 1 X[j][1] [j] X j 1 X[j],X[j+1] = X[j+1],X[j] X[j] X j X[j+1] X j+1 j 1 X[j+1] X j+1 j 1 X[j] X j for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
     i range(n) range n X[i][1] = str(X[i][1]) X[i][1] [i] X i 1 str(X[i][1]) str X[i][1] [i] X i 1 X[i] = "".join(X[i]) X[i] X i "".join(X[i]) "".join "" join X[i] X i return(X) X X X BA = bubble(A) BA bubble(A) bubble A def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS) minsort for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

     i range(n) range n AS[i] = list(AS[i]) AS[i] AS i list(AS[i]) list AS[i] AS i AS[i][1] = int(AS[i][1]) AS[i][1] [i] AS i 1 int(AS[i][1]) int AS[i][1] [i] AS i 1 for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

     i range(n) range n minj = i minj i for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

         j range(i,n) range i n if (AS[j][1] < AS[minj][1]):
                minj = j

         AS[j][1] < AS[minj][1] AS[j][1] [j] AS j 1 AS[minj][1] [minj] AS minj 1 minj = j minj j if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

     minj != i minj i AS[i],AS[minj] = AS[minj],AS[i] AS[i] AS i AS[minj] AS minj AS[minj] AS minj AS[i] AS i for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

     i range(n) range n AS[i][1] = str(AS[i][1]) AS[i][1] [i] AS i 1 str(AS[i][1]) str AS[i][1] [i] AS i 1 AS[i] = "".join(AS[i]) AS[i] AS i "".join(AS[i]) "".join "" join AS[i] AS i return(AS) AS MA = minsort() MA minsort() minsort for k in range(n-1):
    print(str(BA[k])+" ",end = "") k range(n-1) range n-1 n 1 print(str(BA[k])+" ",end = "") print str(BA[k])+" " str(BA[k]) str BA[k] BA k " " end = "" end "" print(str(BA[n-1])) print str(BA[n-1]) str BA[n-1] BA n-1 n 1 print("Stable") print "Stable" for k in range(n-1):
    print(str(MA[k])+" ",end = "") k range(n-1) range n-1 n 1 print(str(MA[k])+" ",end = "") print str(MA[k])+" " str(MA[k]) str MA[k] MA k " " end = "" end "" print(str(MA[n-1])) print str(MA[n-1]) str MA[n-1] MA n-1 n 1 if (BA == MA):
    print("Stable")
else :
    print("Not stable") BA == MA BA MA print("Stable") print "Stable" print("Not stable") print "Not stable" n = int(input()) int(input()) n AS = cp.copy(A) cp.copy(A) AS A = [str(x) for x in input().split()] [str(x) for x in input().split()] A MA = minsort() minsort() MA def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS) def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS) minsort def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X) def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X) bubble BA = bubble(A) bubble(A) BA
import copy as cp

n = int(input())
A = [str(x) for x in input().split()]
AS = cp.copy(A)


def bubble(X):
    for i in range(n):
        X[i] = list(X[i])
        X[i][1] = int(X[i][1])

    for i in range(n):
        for j in range(n-1):
            if (X[j+1][1] < X[j][1]):
                X[j],X[j+1] = X[j+1],X[j]

    for i in range(n):
        X[i][1] = str(X[i][1])
        X[i] = "".join(X[i])
    return(X)


BA = bubble(A)



def minsort():

    for i in range(n):
        AS[i] = list(AS[i])
        AS[i][1] = int(AS[i][1])

    for i in range(n):
        minj = i
        for j in range(i,n):
            if (AS[j][1] < AS[minj][1]):
                minj = j

        if (minj != i):
            AS[i],AS[minj] = AS[minj],AS[i]

    for i in range(n):
        AS[i][1] = str(AS[i][1])
        AS[i] = "".join(AS[i])

    return(AS)

MA = minsort()


for k in range(n-1):
    print(str(BA[k])+" ",end = "")
print(str(BA[n-1]))
print("Stable")

for k in range(n-1):
    print(str(MA[k])+" ",end = "")
print(str(MA[n-1]))
if (BA == MA):
    print("Stable")
else :
    print("Not stable")

