n = int(input())
lst = input().split()
bub, sel = lst[:], lst[:]
def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable')

for i in range(n):
    m = i
    for j in range(n-1,i,-1):
        if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
    for k in range(i, n):
        if sel[k][1] < sel[m][1]:
            m = k
    if m != i:
        sel[i], sel[m] = sel[m], sel[i]

print(*bub)
stable(bub)
print(*sel)
stable(sel) n = int(input()) n int(input()) int input() input lst = input().split() lst input().split() ().split () input split bub, sel = lst[:], lst[:] bub lst[:] lst : sel lst[:] lst : def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable') stable s, i = 1, n-1 s 1 i n-1 n 1 while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
     s*i s i if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
         sls[i][1] == sls[i-1][1] sls[i][1] [i] sls i 1 sls[i-1][1] [i-1] sls i-1 i 1 1 if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
         lst.index(sls[i]) < lst.index(sls[i-1]) lst.index(sls[i]) lst.index lst index sls[i] sls i lst.index(sls[i-1]) lst.index lst index sls[i-1] sls i-1 i 1 s = 0 s 0 i -= 1 i 1 print('Stable' if s else 'Not stable') print 'Stable' if s else 'Not stable' s 'Stable' 'Not stable' sls sls for i in range(n):
    m = i
    for j in range(n-1,i,-1):
        if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
    for k in range(i, n):
        if sel[k][1] < sel[m][1]:
            m = k
    if m != i:
        sel[i], sel[m] = sel[m], sel[i] i range(n) range n m = i m i for j in range(n-1,i,-1):
        if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
     j range(n-1,i,-1) range n-1 n 1 i -1 if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
     bub[j][1] < bub[j-1][1] bub[j][1] [j] bub j 1 bub[j-1][1] [j-1] bub j-1 j 1 1 bub[j-1:j+1] = bub[j], bub[j-1] bub[j-1:j+1] bub j-1:j+1 j-1 j 1 j+1 j 1 bub[j-1:j+1] = bub[j], bub[j-1] bub[j] bub j bub[j-1] bub j-1 j 1 for k in range(i, n):
        if sel[k][1] < sel[m][1]:
            m = k
     k range(i, n) range i n if sel[k][1] < sel[m][1]:
            m = k
     sel[k][1] < sel[m][1] sel[k][1] [k] sel k 1 sel[m][1] [m] sel m 1 m = k m k if m != i:
        sel[i], sel[m] = sel[m], sel[i] m != i m i sel[i], sel[m] = sel[m], sel[i] sel[i] sel i sel[m] sel m sel[m] sel m sel[i] sel i print(*bub) print *bub bub stable(bub) stable bub print(*sel) print *sel sel stable(sel) stable sel bub, sel = lst[:], lst[:] lst[:] bub m = k k m def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable') def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable') stable sel = lst[:], lst[:] lst[:] sel n = int(input()) int(input()) n m = i i m lst = input().split() input().split() lst
n = int(input())
lst = input().split()
bub, sel = lst[:], lst[:]
def stable(sls):
    s, i = 1, n-1
    while s*i:
        if sls[i][1] == sls[i-1][1]:
            if lst.index(sls[i]) < lst.index(sls[i-1]) :
                s = 0
        i -= 1
    print('Stable' if s else 'Not stable')

for i in range(n):
    m = i
    for j in range(n-1,i,-1):
        if bub[j][1] < bub[j-1][1]:
            bub[j-1:j+1] = bub[j], bub[j-1]
    for k in range(i, n):
        if sel[k][1] < sel[m][1]:
            m = k
    if m != i:
        sel[i], sel[m] = sel[m], sel[i]

print(*bub)
stable(bub)
print(*sel)
stable(sel)