import collections

Card = collections.namedtuple('Card', ['suit', 'value'])


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


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


if __name__ == '__main__':
    n = int(input())
    cards = [Card(suit, int(value)) for suit, value in input().split()]
    stable = sorted(cards, key=lambda a: a.value)

    bubble = bubble_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in bubble))
    print('Stable' if bubble == stable else 'Not stable')

    selection = selection_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in selection))
    print('Stable' if selection == stable else 'Not stable') import collections collections Card = collections.namedtuple('Card', ['suit', 'value']) Card collections.namedtuple('Card', ['suit', 'value']) collections.namedtuple collections namedtuple 'Card' ['suit', 'value'] 'suit' 'value' def bubble_sort(array):
    a = array[::]
    for i in range(len(a)):
        for j in reversed(range(i + 1, len(a))):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a bubble_sort a = array[::] a array[::] array :: for i in range(len(a)):
        for j in reversed(range(i + 1, len(a))):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
     i range(len(a)) range len(a) len a for j in reversed(range(i + 1, len(a))):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
     j reversed(range(i + 1, len(a))) reversed range(i + 1, len(a)) range i + 1 i 1 len(a) len a 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 array array def selection_sort(array):
    a = array[::]
    for i in range(len(a)):
        min_j = i
        for j in range(i, len(a)):
            if a[j].value < a[min_j].value:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
    return a selection_sort a = array[::] a array[::] array :: for i in range(len(a)):
        min_j = i
        for j in range(i, len(a)):
            if a[j].value < a[min_j].value:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
     i range(len(a)) range len(a) len a min_j = i min_j i for j in range(i, len(a)):
            if a[j].value < a[min_j].value:
                min_j = j
         j range(i, len(a)) range i len(a) len a if a[j].value < a[min_j].value:
                min_j = j
         a[j].value < a[min_j].value a[j].value [j] a j value a[min_j].value [min_j] a min_j value min_j = j min_j j a[i], a[min_j] = a[min_j], a[i] a[i] a i a[min_j] a min_j a[min_j] a min_j a[i] a i return a a array array if __name__ == '__main__':
    n = int(input())
    cards = [Card(suit, int(value)) for suit, value in input().split()]
    stable = sorted(cards, key=lambda a: a.value)

    bubble = bubble_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in bubble))
    print('Stable' if bubble == stable else 'Not stable')

    selection = selection_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in selection))
    print('Stable' if selection == stable else 'Not stable') __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input Card(suit, int(value)) for suit, value in input().split() for suit, value in input().split() suit value input().split() ().split () input split for suit, value in input().split() Card(suit, int(value)) Card suit int(value) int value cards = [Card(suit, int(value)) for suit, value in input().split()] cards [Card(suit, int(value)) for suit, value in input().split()] stable = sorted(cards, key=lambda a: a.value) stable sorted(cards, key=lambda a: a.value) sorted cards key=lambda a: a.value key lambda a: a.value a.value a value a bubble = bubble_sort(cards) bubble bubble_sort(cards) bubble_sort cards print(' '.join(''.join(map(str, card)) for card in bubble)) print ' '.join(''.join(map(str, card)) for card in bubble) ' '.join ' ' join ''.join(map(str, card)) ''.join '' join map(str, card) map str card print('Stable' if bubble == stable else 'Not stable') print 'Stable' if bubble == stable else 'Not stable' bubble == stable bubble stable 'Stable' 'Not stable' selection = selection_sort(cards) selection selection_sort(cards) selection_sort cards print(' '.join(''.join(map(str, card)) for card in selection)) print ' '.join(''.join(map(str, card)) for card in selection) ' '.join ' ' join ''.join(map(str, card)) ''.join '' join map(str, card) map str card print('Stable' if selection == stable else 'Not stable') print 'Stable' if selection == stable else 'Not stable' selection == stable selection stable 'Stable' 'Not stable' selection = selection_sort(cards) selection_sort(cards) selection def bubble_sort(array):
    a = array[::]
    for i in range(len(a)):
        for j in reversed(range(i + 1, len(a))):
            if a[j].value < a[j - 1].value:
                a[j], a[j - 1] = a[j - 1], a[j]
    return a def bubble_sort(array):
    a = array[::]
    for i in range(len(a)):
        for j in reversed(range(i + 1, len(a))):
            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 bubble = bubble_sort(cards) bubble_sort(cards) bubble cards = [Card(suit, int(value)) for suit, value in input().split()] [Card(suit, int(value)) for suit, value in input().split()] cards stable = sorted(cards, key=lambda a: a.value) sorted(cards, key=lambda a: a.value) stable Card = collections.namedtuple('Card', ['suit', 'value']) collections.namedtuple('Card', ['suit', 'value']) Card def selection_sort(array):
    a = array[::]
    for i in range(len(a)):
        min_j = i
        for j in range(i, len(a)):
            if a[j].value < a[min_j].value:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
    return a def selection_sort(array):
    a = array[::]
    for i in range(len(a)):
        min_j = i
        for j in range(i, len(a)):
            if a[j].value < a[min_j].value:
                min_j = j
        a[i], a[min_j] = a[min_j], a[i]
    return a selection_sort
import collections

Card = collections.namedtuple('Card', ['suit', 'value'])


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


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


if __name__ == '__main__':
    n = int(input())
    cards = [Card(suit, int(value)) for suit, value in input().split()]
    stable = sorted(cards, key=lambda a: a.value)

    bubble = bubble_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in bubble))
    print('Stable' if bubble == stable else 'Not stable')

    selection = selection_sort(cards)
    print(' '.join(''.join(map(str, card)) for card in selection))
    print('Stable' if selection == stable else 'Not stable')