def sep(Nf, Mf):
    mm = [[] for _ in range(9)]
    for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
    return mm


def ssort(L, N, M):
    for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i]


def bsort(L, N, M):
    for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j]


n = int(input())
L = list(input().split())
N = [int(i[1]) for i in L]
M = [i[0] for i in L]
marks = ['S', 'H', 'C' ,'D']
Lb, Nb, Mb = L[:], N[:], M[:]
bsort(Lb, Nb, Mb)
print(' '.join(Lb))
if sep(N, M) == sep(Nb, Mb):
    print('Stable')
else:
    print('Not stable')

Ls, Ns, Ms = L[:], N[:], M[:]
ssort(Ls, Ns, Ms)
print(' '.join(Ls))
if sep(N, M) == sep(Ns, Ms):
    print('Stable')
else:
    print('Not stable') def sep(Nf, Mf):
    mm = [[] for _ in range(9)]
    for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
    return mm sep [] for _ in range(9) for _ in range(9) _ range(9) range 9 for _ in range(9) [] mm = [[] for _ in range(9)] mm [[] for _ in range(9)] for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
     m range(len(Nf)) range len(Nf) len Nf for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
     i range(9) range 9 if Nf[m] == i+1:
                mm[i].append(Mf[m])
     Nf[m] == i+1 Nf[m] Nf m i+1 i 1 mm[i].append(Mf[m]) [i].append [i] mm i append Mf[m] Mf m return mm mm Nf Nf Mf Mf def ssort(L, N, M):
    for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i] ssort for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i] i range(len(N)-1) range len(N)-1 len(N) len N 1 x = N[i+1:].index(min(N[i+1:])) + i + 1 x N[i+1:].index(min(N[i+1:])) + i + 1 N[i+1:].index(min(N[i+1:])) + i N[i+1:].index(min(N[i+1:])) [i+1:].index [i+1:] N i+1: i+1 i 1 index min(N[i+1:]) min N[i+1:] N i+1: i+1 i 1 i 1 if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i] N[i] > N[x] N[i] N i N[x] N x L[i], L[x] = L[x], L[i] L[i] L i L[x] L x L[x] L x L[i] L i N[i], N[x] = N[x], N[i] N[i] N i N[x] N x N[x] N x N[i] N i M[i], M[x] = M[x], M[i] M[i] M i M[x] M x M[x] M x M[i] M i L L N N M M def bsort(L, N, M):
    for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] bsort for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] i range(len(N)-1) range len(N)-1 len(N) len N 1 for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] j range(len(N)-1-i) range len(N)-1-i len(N)-1 len(N) len N 1 i if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] N[j] > N[j+1] N[j] N j N[j+1] N j+1 j 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 N[j], N[j+1] = N[j+1], N[j] N[j] N j N[j+1] N j+1 j 1 N[j+1] N j+1 j 1 N[j] N j M[j], M[j+1] = M[j+1], M[j] M[j] M j M[j+1] M j+1 j 1 M[j+1] M j+1 j 1 M[j] M j L L N N M M n = int(input()) n int(input()) int input() input L = list(input().split()) L list(input().split()) list input().split() ().split () input split int(i[1]) for i in L for i in L i L for i in L int(i[1]) int i[1] i 1 N = [int(i[1]) for i in L] N [int(i[1]) for i in L] i[0] for i in L for i in L i L for i in L i[0] i 0 M = [i[0] for i in L] M [i[0] for i in L] marks = ['S', 'H', 'C' ,'D'] marks ['S', 'H', 'C' ,'D'] 'S' 'H' 'C' 'D' Lb, Nb, Mb = L[:], N[:], M[:] Lb L[:] L : Nb N[:] N : Mb M[:] M : bsort(Lb, Nb, Mb) bsort Lb Nb Mb print(' '.join(Lb)) print ' '.join(Lb) ' '.join ' ' join Lb if sep(N, M) == sep(Nb, Mb):
    print('Stable')
else:
    print('Not stable') sep(N, M) == sep(Nb, Mb) sep(N, M) sep N M sep(Nb, Mb) sep Nb Mb print('Stable') print 'Stable' print('Not stable') print 'Not stable' Ls, Ns, Ms = L[:], N[:], M[:] Ls L[:] L : Ns N[:] N : Ms M[:] M : ssort(Ls, Ns, Ms) ssort Ls Ns Ms print(' '.join(Ls)) print ' '.join(Ls) ' '.join ' ' join Ls if sep(N, M) == sep(Ns, Ms):
    print('Stable')
else:
    print('Not stable') sep(N, M) == sep(Ns, Ms) sep(N, M) sep N M sep(Ns, Ms) sep Ns Ms print('Stable') print 'Stable' print('Not stable') print 'Not stable' def sep(Nf, Mf):
    mm = [[] for _ in range(9)]
    for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
    return mm def sep(Nf, Mf):
    mm = [[] for _ in range(9)]
    for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
    return mm sep marks = ['S', 'H', 'C' ,'D'] ['S', 'H', 'C' ,'D'] marks Ms = L[:], N[:], M[:] M[:] Ms N = [int(i[1]) for i in L] [int(i[1]) for i in L] N Mb = L[:], N[:], M[:] M[:] Mb L = list(input().split()) list(input().split()) L M = [i[0] for i in L] [i[0] for i in L] M n = int(input()) int(input()) n Lb, Nb, Mb = L[:], N[:], M[:] L[:] Lb def ssort(L, N, M):
    for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i] def ssort(L, N, M):
    for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i] ssort Ls, Ns, Ms = L[:], N[:], M[:] L[:] Ls Ns, Ms = L[:], N[:], M[:] N[:] Ns def bsort(L, N, M):
    for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] def bsort(L, N, M):
    for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j] bsort Nb, Mb = L[:], N[:], M[:] N[:] Nb
def sep(Nf, Mf):
    mm = [[] for _ in range(9)]
    for m in range(len(Nf)):
        for i in range(9):
            if Nf[m] == i+1:
                mm[i].append(Mf[m])
    return mm


def ssort(L, N, M):
    for i in range(len(N)-1):
        x = N[i+1:].index(min(N[i+1:])) + i + 1
        if N[i] > N[x]:
            L[i], L[x] = L[x], L[i]
            N[i], N[x] = N[x], N[i]
            M[i], M[x] = M[x], M[i]


def bsort(L, N, M):
    for i in range(len(N)-1):
        for j in range(len(N)-1-i):
            if N[j] > N[j+1]:
                L[j], L[j+1] = L[j+1], L[j]
                N[j], N[j+1] = N[j+1], N[j]
                M[j], M[j+1] = M[j+1], M[j]


n = int(input())
L = list(input().split())
N = [int(i[1]) for i in L]
M = [i[0] for i in L]
marks = ['S', 'H', 'C' ,'D']
Lb, Nb, Mb = L[:], N[:], M[:]
bsort(Lb, Nb, Mb)
print(' '.join(Lb))
if sep(N, M) == sep(Nb, Mb):
    print('Stable')
else:
    print('Not stable')

Ls, Ns, Ms = L[:], N[:], M[:]
ssort(Ls, Ns, Ms)
print(' '.join(Ls))
if sep(N, M) == sep(Ns, Ms):
    print('Stable')
else:
    print('Not stable')
