from collections import namedtuple
from operator import itemgetter, attrgetter

def bubble_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a


def selection_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a

class Card(namedtuple('Card', ['suit', 'value'])):
    def __str__(self):
        return '{0}{1}'.format(self.suit, self.value)

parser = lambda s: Card(s[0], int(s[1:]))

n = int(input())
a = list(map(parser, input().split()))

stable_sorted = sorted(a, key = attrgetter('value'))
bubble_sorted = bubble_sort(a)
selection_sorted = selection_sort(a)

print(' '.join(list(map(str, bubble_sorted))))
if stable_sorted == bubble_sorted:
    print('Stable')
else:
    print('Not stable')

print(' '.join(list(map(str, selection_sorted))))
if stable_sorted == selection_sorted:
    print('Stable')
else:
    print('Not stable') from collections import namedtuple from operator import itemgetter, attrgetter def bubble_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a bubble_sort a = a[:] a a[:] a : n = len(a) n len(a) len a for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
     i range(n) range n for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
     j range(n - 1, i, -1) range n - 1 n 1 i -1 if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
     a[j].value < a[j - 1].value a[j].value [j] a j value a[j - 1].value [j - 1] a j - 1 j 1 value a[j], a[j - 1] = a[j - 1], a[j] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] a j - 1 j 1 a[j] a j return a a a a def selection_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a selection_sort a = a[:] a a[:] a : n = len(a) n len(a) len a for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

     i range(n) range n minj = i minj i for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
         j range(i, n) range i n if a[j].value < a[minj].value:
                minj = j
         a[j].value < a[minj].value a[j].value [j] a j value a[minj].value [minj] a minj value minj = j minj j a[i], a[minj] = a[minj], a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i return a a a a class Card(namedtuple('Card', ['suit', 'value'])):
    def __str__(self):
        return '{0}{1}'.format(self.suit, self.value) Card def __str__(self):
        return '{0}{1}'.format(self.suit, self.value) __str__ return '{0}{1}'.format(self.suit, self.value) '{0}{1}'.format(self.suit, self.value) '{0}{1}'.format '{0}{1}' format self.suit self suit self.value self value self self namedtuple('Card', ['suit', 'value']) namedtuple 'Card' ['suit', 'value'] 'suit' 'value' parser = lambda s: Card(s[0], int(s[1:])) parser lambda s: Card(s[0], int(s[1:])) Card(s[0], int(s[1:])) Card s[0] s 0 int(s[1:]) int s[1:] s 1: 1 s n = int(input()) n int(input()) int input() input a = list(map(parser, input().split())) a list(map(parser, input().split())) list map(parser, input().split()) map parser input().split() ().split () input split stable_sorted = sorted(a, key = attrgetter('value')) stable_sorted sorted(a, key = attrgetter('value')) sorted a key = attrgetter('value') key attrgetter('value') attrgetter 'value' bubble_sorted = bubble_sort(a) bubble_sorted bubble_sort(a) bubble_sort a selection_sorted = selection_sort(a) selection_sorted selection_sort(a) selection_sort a print(' '.join(list(map(str, bubble_sorted)))) print ' '.join(list(map(str, bubble_sorted))) ' '.join ' ' join list(map(str, bubble_sorted)) list map(str, bubble_sorted) map str bubble_sorted if stable_sorted == bubble_sorted:
    print('Stable')
else:
    print('Not stable') stable_sorted == bubble_sorted stable_sorted bubble_sorted print('Stable') print 'Stable' print('Not stable') print 'Not stable' print(' '.join(list(map(str, selection_sorted)))) print ' '.join(list(map(str, selection_sorted))) ' '.join ' ' join list(map(str, selection_sorted)) list map(str, selection_sorted) map str selection_sorted if stable_sorted == selection_sorted:
    print('Stable')
else:
    print('Not stable') stable_sorted == selection_sorted stable_sorted selection_sorted print('Stable') print 'Stable' print('Not stable') print 'Not stable' parser = lambda s: Card(s[0], int(s[1:])) lambda s: Card(s[0], int(s[1:])) parser selection_sorted = selection_sort(a) selection_sort(a) selection_sorted a = list(map(parser, input().split())) list(map(parser, input().split())) a class Card(namedtuple('Card', ['suit', 'value'])):
    def __str__(self):
        return '{0}{1}'.format(self.suit, self.value) class Card(namedtuple('Card', ['suit', 'value'])):
    def __str__(self):
        return '{0}{1}'.format(self.suit, self.value) Card stable_sorted = sorted(a, key = attrgetter('value')) sorted(a, key = attrgetter('value')) stable_sorted def bubble_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a def bubble_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a bubble_sort n = int(input()) int(input()) n def selection_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a def selection_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a selection_sort bubble_sorted = bubble_sort(a) bubble_sort(a) bubble_sorted
from collections import namedtuple
from operator import itemgetter, attrgetter

def bubble_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        for j in range(n - 1, i, -1):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a


def selection_sort(a):
    a = a[:]
    n = len(a)

    for i in range(n):
        minj = i
        for j in range(i, n):
            if a[j].value < a[minj].value:
                minj = j
        a[i], a[minj] = a[minj], a[i]

    return a

class Card(namedtuple('Card', ['suit', 'value'])):
    def __str__(self):
        return '{0}{1}'.format(self.suit, self.value)

parser = lambda s: Card(s[0], int(s[1:]))

n = int(input())
a = list(map(parser, input().split()))

stable_sorted = sorted(a, key = attrgetter('value'))
bubble_sorted = bubble_sort(a)
selection_sorted = selection_sort(a)

print(' '.join(list(map(str, bubble_sorted))))
if stable_sorted == bubble_sorted:
    print('Stable')
else:
    print('Not stable')

print(' '.join(list(map(str, selection_sorted))))
if stable_sorted == selection_sorted:
    print('Stable')
else:
    print('Not stable')