def ssort(L, n):
    L = L[:]
    for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
    return L

def bsort(L, n):
    L = L[:]
    for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
    return L

def is_stable(L_in, L_out):
    in_pair_list= []
    out_pair_list= []
    for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
    for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
    return not bool(set(in_pair_list) - set(out_pair_list))

def print_stable(b):
    print('Stable' if b else 'Not stable')

n = int(input())
L = input().split()

b = bsort(L, n)
print(*b)
print_stable(is_stable(L, b))
s = ssort(L, n)
print(*s)
print_stable(is_stable(L, s)) def ssort(L, n):
    L = L[:]
    for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
    return L ssort L = L[:] L L[:] L : for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
     i range(n) range n minj = i minj i for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
         j range(i, n) range i n if L[j][1] < L[minj][1]:
                minj = j
         L[j][1] < L[minj][1] L[j][1] [j] L j 1 L[minj][1] [minj] L minj 1 minj = j minj j L[i], L[minj] = L[minj], L[i] L[i] L i L[minj] L minj L[minj] L minj L[i] L i return L L L L n n def bsort(L, n):
    L = L[:]
    for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
    return L bsort L = L[:] L L[:] L : for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
     _ L for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
     j range(n-1, 0, -1) range n-1 n 1 0 -1 if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
     L[j][1] < L[j-1][1] L[j][1] [j] L j 1 L[j-1][1] [j-1] L j-1 j 1 1 L[j], L[j-1] = L[j-1], L[j] L[j] L j L[j-1] L j-1 j 1 L[j-1] L j-1 j 1 L[j] L j return L L L L n n def is_stable(L_in, L_out):
    in_pair_list= []
    out_pair_list= []
    for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
    for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
    return not bool(set(in_pair_list) - set(out_pair_list)) is_stable in_pair_list= [] in_pair_list [] out_pair_list= [] out_pair_list [] for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
     i e1 enumerate(L_in) enumerate L_in for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
     j e2 enumerate(L_in[i+1:]) enumerate L_in[i+1:] L_in i+1: i+1 i 1 if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
     e1[1] == e2[1] e1[1] e1 1 e2[1] e2 1 in_pair_list.append((e1, e2)) in_pair_list.append in_pair_list append (e1, e2) e1 e2 for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
     i e1 enumerate(L_out) enumerate L_out for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
     j e2 enumerate(L_out[i+1:]) enumerate L_out[i+1:] L_out i+1: i+1 i 1 if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
     e1[1] == e2[1] e1[1] e1 1 e2[1] e2 1 out_pair_list.append((e1, e2)) out_pair_list.append out_pair_list append (e1, e2) e1 e2 return not bool(set(in_pair_list) - set(out_pair_list)) not bool(set(in_pair_list) - set(out_pair_list)) bool(set(in_pair_list) - set(out_pair_list)) bool set(in_pair_list) - set(out_pair_list) set(in_pair_list) set in_pair_list set(out_pair_list) set out_pair_list L_in L_in L_out L_out def print_stable(b):
    print('Stable' if b else 'Not stable') print_stable print('Stable' if b else 'Not stable') print 'Stable' if b else 'Not stable' b 'Stable' 'Not stable' b b n = int(input()) n int(input()) int input() input L = input().split() L input().split() ().split () input split b = bsort(L, n) b bsort(L, n) bsort L n print(*b) print *b b print_stable(is_stable(L, b)) print_stable is_stable(L, b) is_stable L b s = ssort(L, n) s ssort(L, n) ssort L n print(*s) print *s s print_stable(is_stable(L, s)) print_stable is_stable(L, s) is_stable L s n = int(input()) int(input()) n s = ssort(L, n) ssort(L, n) s def is_stable(L_in, L_out):
    in_pair_list= []
    out_pair_list= []
    for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
    for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
    return not bool(set(in_pair_list) - set(out_pair_list)) def is_stable(L_in, L_out):
    in_pair_list= []
    out_pair_list= []
    for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
    for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
    return not bool(set(in_pair_list) - set(out_pair_list)) is_stable def print_stable(b):
    print('Stable' if b else 'Not stable') def print_stable(b):
    print('Stable' if b else 'Not stable') print_stable def ssort(L, n):
    L = L[:]
    for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
    return L def ssort(L, n):
    L = L[:]
    for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
    return L ssort L = input().split() input().split() L b = bsort(L, n) bsort(L, n) b def bsort(L, n):
    L = L[:]
    for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
    return L def bsort(L, n):
    L = L[:]
    for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
    return L bsort
def ssort(L, n):
    L = L[:]
    for i in range(n):
        minj = i
        for j in range(i, n):
            if L[j][1] < L[minj][1]:
                minj = j
        L[i], L[minj] = L[minj], L[i]
    return L

def bsort(L, n):
    L = L[:]
    for _ in L:
        for j in range(n-1, 0, -1):
            if L[j][1] < L[j-1][1]:
                L[j], L[j-1] = L[j-1], L[j]
    return L

def is_stable(L_in, L_out):
    in_pair_list= []
    out_pair_list= []
    for i, e1 in enumerate(L_in):
        for j, e2 in enumerate(L_in[i+1:]):
            if e1[1] == e2[1]:
                in_pair_list.append((e1, e2))
    for i, e1 in enumerate(L_out):
        for j, e2 in enumerate(L_out[i+1:]):
            if e1[1] == e2[1]:
                out_pair_list.append((e1, e2))
    return not bool(set(in_pair_list) - set(out_pair_list))

def print_stable(b):
    print('Stable' if b else 'Not stable')

n = int(input())
L = input().split()

b = bsort(L, n)
print(*b)
print_stable(is_stable(L, b))
s = ssort(L, n)
print(*s)
print_stable(is_stable(L, s))