length = int(input())
eles = [l for l in input().split()]
is_stable = 'Stable'

import copy
_copy = copy.deepcopy(eles)

for i in range(length):
    for j in range(length-1, 0, -1):
        if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j]

print(*_copy)
print(is_stable)

__copy = copy.deepcopy(eles)
for i in range(length-1):
    _min = i
    for l in range(i, length):
        if __copy[l][1] < __copy[_min][1]:
            _min = l
    if __copy[i][1] > __copy[_min][1]:
        __copy[i], __copy[_min] = __copy[_min], __copy[i]

print(*__copy)

for i in range(length -1):
    if _copy[i] != __copy[i]:
        is_stable = 'Not stable'

print(is_stable) length = int(input()) length int(input()) int input() input l for l in input().split() for l in input().split() l input().split() ().split () input split for l in input().split() l eles = [l for l in input().split()] eles [l for l in input().split()] is_stable = 'Stable' is_stable 'Stable' import copy copy _copy = copy.deepcopy(eles) _copy copy.deepcopy(eles) copy.deepcopy copy deepcopy eles for i in range(length):
    for j in range(length-1, 0, -1):
        if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j] i range(length) range length for j in range(length-1, 0, -1):
        if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j] j range(length-1, 0, -1) range length-1 length 1 0 -1 if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j] _copy[j][1] < _copy[j-1][1] _copy[j][1] [j] _copy j 1 _copy[j-1][1] [j-1] _copy j-1 j 1 1 _copy[j], _copy[j-1] = _copy[j-1], _copy[j] _copy[j] _copy j _copy[j-1] _copy j-1 j 1 _copy[j-1] _copy j-1 j 1 _copy[j] _copy j print(*_copy) print *_copy _copy print(is_stable) print is_stable __copy = copy.deepcopy(eles) __copy copy.deepcopy(eles) copy.deepcopy copy deepcopy eles for i in range(length-1):
    _min = i
    for l in range(i, length):
        if __copy[l][1] < __copy[_min][1]:
            _min = l
    if __copy[i][1] > __copy[_min][1]:
        __copy[i], __copy[_min] = __copy[_min], __copy[i] i range(length-1) range length-1 length 1 _min = i _min i for l in range(i, length):
        if __copy[l][1] < __copy[_min][1]:
            _min = l
     l range(i, length) range i length if __copy[l][1] < __copy[_min][1]:
            _min = l
     __copy[l][1] < __copy[_min][1] __copy[l][1] [l] __copy l 1 __copy[_min][1] [_min] __copy _min 1 _min = l _min l if __copy[i][1] > __copy[_min][1]:
        __copy[i], __copy[_min] = __copy[_min], __copy[i] __copy[i][1] > __copy[_min][1] __copy[i][1] [i] __copy i 1 __copy[_min][1] [_min] __copy _min 1 __copy[i], __copy[_min] = __copy[_min], __copy[i] __copy[i] __copy i __copy[_min] __copy _min __copy[_min] __copy _min __copy[i] __copy i print(*__copy) print *__copy __copy for i in range(length -1):
    if _copy[i] != __copy[i]:
        is_stable = 'Not stable' i range(length -1) range length -1 length 1 if _copy[i] != __copy[i]:
        is_stable = 'Not stable' _copy[i] != __copy[i] _copy[i] _copy i __copy[i] __copy i is_stable = 'Not stable' is_stable 'Not stable' print(is_stable) print is_stable eles = [l for l in input().split()] [l for l in input().split()] eles _copy = copy.deepcopy(eles) copy.deepcopy(eles) _copy is_stable = 'Stable' 'Stable' is_stable length = int(input()) int(input()) length _min = l l _min _min = i i _min is_stable = 'Not stable' 'Not stable' is_stable
length = int(input())
eles = [l for l in input().split()]
is_stable = 'Stable'

import copy
_copy = copy.deepcopy(eles)

for i in range(length):
    for j in range(length-1, 0, -1):
        if _copy[j][1] < _copy[j-1][1]:
            _copy[j], _copy[j-1] = _copy[j-1], _copy[j]

print(*_copy)
print(is_stable)

__copy = copy.deepcopy(eles)
for i in range(length-1):
    _min = i
    for l in range(i, length):
        if __copy[l][1] < __copy[_min][1]:
            _min = l
    if __copy[i][1] > __copy[_min][1]:
        __copy[i], __copy[_min] = __copy[_min], __copy[i]

print(*__copy)

for i in range(length -1):
    if _copy[i] != __copy[i]:
        is_stable = 'Not stable'

print(is_stable)