def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards

def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards

n = int(input())
cards = input().split()
bubble_cards = bubble_sort(cards)
selection_cards = selection_sort(cards)

print(' '.join(bubble_cards))
print('Stable')
print(' '.join(selection_cards))
if bubble_cards == selection_cards:
    print('Stable')
else:
    print('Not stable') def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards bubble_sort i for i in card_list for i in card_list i card_list for i in card_list i cards = [i for i in card_list] cards [i for i in card_list] list_length = len(cards) list_length len(cards) len cards for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
     i range(list_length) range list_length for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
     j range(list_length-1,i,-1) range list_length-1 list_length 1 i -1 if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
     int(cards[j][1:]) < int(cards[j-1][1:]) int(cards[j][1:]) int cards[j][1:] [j] cards j 1: 1 int(cards[j-1][1:]) int cards[j-1][1:] [j-1] cards j-1 j 1 1: 1 cards[j],cards[j-1] = cards[j-1],cards[j] cards[j] cards j cards[j-1] cards j-1 j 1 cards[j-1] cards j-1 j 1 cards[j] cards j return cards cards card_list card_list def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards selection_sort i for i in card_list for i in card_list i card_list for i in card_list i cards = [i for i in card_list] cards [i for i in card_list] list_length = len(cards) list_length len(cards) len cards for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
     i range(list_length) range list_length min_element = i min_element i for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
         j range(i+1,list_length) range i+1 i 1 list_length if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
         int(cards[j][1:]) < int(cards[min_element][1:]) int(cards[j][1:]) int cards[j][1:] [j] cards j 1: 1 int(cards[min_element][1:]) int cards[min_element][1:] [min_element] cards min_element 1: 1 min_element = j min_element j cards[i],cards[min_element] = cards[min_element],cards[i] cards[i] cards i cards[min_element] cards min_element cards[min_element] cards min_element cards[i] cards i return cards cards card_list card_list n = int(input()) n int(input()) int input() input cards = input().split() cards input().split() ().split () input split bubble_cards = bubble_sort(cards) bubble_cards bubble_sort(cards) bubble_sort cards selection_cards = selection_sort(cards) selection_cards selection_sort(cards) selection_sort cards print(' '.join(bubble_cards)) print ' '.join(bubble_cards) ' '.join ' ' join bubble_cards print('Stable') print 'Stable' print(' '.join(selection_cards)) print ' '.join(selection_cards) ' '.join ' ' join selection_cards if bubble_cards == selection_cards:
    print('Stable')
else:
    print('Not stable') bubble_cards == selection_cards bubble_cards selection_cards print('Stable') print 'Stable' print('Not stable') print 'Not stable' n = int(input()) int(input()) n selection_cards = selection_sort(cards) selection_sort(cards) selection_cards def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards selection_sort cards = input().split() input().split() cards def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards bubble_sort bubble_cards = bubble_sort(cards) bubble_sort(cards) bubble_cards
def bubble_sort(card_list):
    cards = [i for i in card_list]
    list_length = len(cards)

    for i in range(list_length):
        for j in range(list_length-1,i,-1):
            if int(cards[j][1:]) < int(cards[j-1][1:]):
                cards[j],cards[j-1] = cards[j-1],cards[j]
    return cards

def selection_sort(card_list):
    cards = [i for i in card_list]

    list_length = len(cards)

    for i in range(list_length):
        min_element = i
        for j in range(i+1,list_length):
            if int(cards[j][1:]) < int(cards[min_element][1:]):
                min_element = j
        cards[i],cards[min_element] = cards[min_element],cards[i]
    return cards

n = int(input())
cards = input().split()
bubble_cards = bubble_sort(cards)
selection_cards = selection_sort(cards)

print(' '.join(bubble_cards))
print('Stable')
print(' '.join(selection_cards))
if bubble_cards == selection_cards:
    print('Stable')
else:
    print('Not stable')
