def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j]

def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i]

n = int(input())
a = list(map(str, input().split()))

b = a.copy()
c = a.copy()

bubble(b)
selection(c)

for d in [b, c]:
    print(" ".join(d))
    if d == b:
        print("Stable")
    else:
        print("Not stable") def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] bubble for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] i range(len(d) - 1) range len(d) - 1 len(d) len d 1 for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] j range(len(d) - 1, i, -1) range len(d) - 1 len(d) len d 1 i -1 if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] int(d[j][1]) < int(d[j - 1][1]) int(d[j][1]) int d[j][1] [j] d j 1 int(d[j - 1][1]) int d[j - 1][1] [j - 1] d j - 1 j 1 1 d[j],d[j - 1] = d[j - 1],d[j] d[j] d j d[j - 1] d j - 1 j 1 d[j - 1] d j - 1 j 1 d[j] d j d d def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i] selection for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i] i range(len(b)) range len(b) len b min_j = i min_j i for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
         j range(i, len(d)) range i len(d) len d if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
         int(d[j][1]) < int(d[min_j][1]) int(d[j][1]) int d[j][1] [j] d j 1 int(d[min_j][1]) int d[min_j][1] [min_j] d min_j 1 min_j = j min_j j if min_j != i:
            d[i],d[min_j] = d[min_j], d[i] min_j != i min_j i d[i],d[min_j] = d[min_j], d[i] d[i] d i d[min_j] d min_j d[min_j] d min_j d[i] d i d d n = int(input()) n int(input()) int input() input a = list(map(str, input().split())) a list(map(str, input().split())) list map(str, input().split()) map str input().split() ().split () input split b = a.copy() b a.copy() a.copy a copy c = a.copy() c a.copy() a.copy a copy bubble(b) bubble b selection(c) selection c for d in [b, c]:
    print(" ".join(d))
    if d == b:
        print("Stable")
    else:
        print("Not stable") d [b, c] b c print(" ".join(d)) print " ".join(d) " ".join " " join d if d == b:
        print("Stable")
    else:
        print("Not stable") d == b d b print("Stable") print "Stable" print("Not stable") print "Not stable" def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j] bubble a = list(map(str, input().split())) list(map(str, input().split())) a c = a.copy() a.copy() c def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i] def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i] selection n = int(input()) int(input()) n b = a.copy() a.copy() b
def bubble(d):
    for i in range(len(d) - 1):
        for j in range(len(d) - 1, i, -1):
            if int(d[j][1]) < int(d[j - 1][1]):
                d[j],d[j - 1] = d[j - 1],d[j]

def selection(d):
    for i in range(len(b)):
        min_j = i
        for j in range(i, len(d)):
            if int(d[j][1]) < int(d[min_j][1]):
                min_j = j
        if min_j != i:
            d[i],d[min_j] = d[min_j], d[i]

n = int(input())
a = list(map(str, input().split()))

b = a.copy()
c = a.copy()

bubble(b)
selection(c)

for d in [b, c]:
    print(" ".join(d))
    if d == b:
        print("Stable")
    else:
        print("Not stable")