def bubbleSort(c):
    for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
    return c


def selectionSort(c):
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c


n = int(input())
b = input().split()
s = b[:]

b = bubbleSort(b)
s = selectionSort(s)

print(*b)
print('Stable')
print(*s)
print('Stable' if b == s else 'Not stable')
 def bubbleSort(c):
    for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
    return c bubbleSort for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
     i range(len(c)) range len(c) len c for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
     j range(len(c) - 1, i, -1) range len(c) - 1 len(c) len c 1 i -1 if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
     c[j][1] < c[j - 1][1] c[j][1] [j] c j 1 c[j - 1][1] [j - 1] c j - 1 j 1 1 c[j], c[j - 1] = c[j - 1], c[j] c[j] c j c[j - 1] c j - 1 j 1 c[j - 1] c j - 1 j 1 c[j] c j return c c c c def selectionSort(c):
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c selectionSort for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
     i range(len(c)) range len(c) len c minj = i minj i for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
         j range(i, len(c)) range i len(c) len c if c[j][1] < c[minj][1]:
                minj = j
         c[j][1] < c[minj][1] c[j][1] [j] c j 1 c[minj][1] [minj] c minj 1 minj = j minj j c[i], c[minj] = c[minj], c[i] c[i] c i c[minj] c minj c[minj] c minj c[i] c i return c c c c n = int(input()) n int(input()) int input() input b = input().split() b input().split() ().split () input split s = b[:] s b[:] b : b = bubbleSort(b) b bubbleSort(b) bubbleSort b s = selectionSort(s) s selectionSort(s) selectionSort s print(*b) print *b b print('Stable') print 'Stable' print(*s) print *s s print('Stable' if b == s else 'Not stable') print 'Stable' if b == s else 'Not stable' b == s b s 'Stable' 'Not stable' def selectionSort(c):
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c def selectionSort(c):
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c selectionSort b = bubbleSort(b) bubbleSort(b) b b = input().split() input().split() b n = int(input()) int(input()) n def bubbleSort(c):
    for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
    return c def bubbleSort(c):
    for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
    return c bubbleSort s = selectionSort(s) selectionSort(s) s s = b[:] b[:] s
def bubbleSort(c):
    for i in range(len(c)):
        for j in range(len(c) - 1, i, -1):
            if c[j][1] < c[j - 1][1]:
                c[j], c[j - 1] = c[j - 1], c[j]
    return c


def selectionSort(c):
    for i in range(len(c)):
        minj = i
        for j in range(i, len(c)):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c


n = int(input())
b = input().split()
s = b[:]

b = bubbleSort(b)
s = selectionSort(s)

print(*b)
print('Stable')
print(*s)
print('Stable' if b == s else 'Not stable')

