N = int(input())
C1 = list(input().split()) 
C2 = C1[:]

def get_card_suit(card):
    return card[:1]

def get_card_value(card):
    return card[1:]

def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1

def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1

def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip())

def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True

bubble_sort(C1)
select_sort(C2)

output(C1)
print('Stable')

output(C2)
if is_stable() == True:
    print('Stable')
else:
    print('Not stable')
 N = int(input()) N int(input()) int input() input C1 = list(input().split()) C1 list(input().split()) list input().split() ().split () input split C2 = C1[:] C2 C1[:] C1 : def get_card_suit(card):
    return card[:1] get_card_suit return card[:1] card[:1] card :1 1 card card def get_card_value(card):
    return card[1:] get_card_value return card[1:] card[1:] card 1: 1 card card def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1 bubble_sort r_exists = True r_exists True while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1 r_exists == True r_exists True r_exists = False r_exists False i = N - 1 i N - 1 N 1 while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1 i >= 1 i 1 if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
             get_card_value(card[i]) < get_card_value(card[i - 1]) get_card_value(card[i]) get_card_value card[i] card i get_card_value(card[i - 1]) get_card_value card[i - 1] card i - 1 i 1 card[i], card[i - 1] = card[i - 1], card[i] card[i] card i card[i - 1] card i - 1 i 1 card[i - 1] card i - 1 i 1 card[i] card i r_exists = True r_exists True i -= 1 i 1 card card def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1 select_sort i = 0 i 0 while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1 i < N i N min_j = i min_j i j = i j i while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

         j < N j N if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

             get_card_value(card[j]) < get_card_value(card[min_j]) get_card_value(card[j]) get_card_value card[j] card j get_card_value(card[min_j]) get_card_value card[min_j] card min_j min_j = j min_j j j += 1 j 1 card[i], card[min_j] = card[min_j], card[i] card[i] card i card[min_j] card min_j card[min_j] card min_j card[i] card i i += 1 i 1 card card def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip()) output s = '' s '' for x in card:

        s = s + str(x) + ' '

     x card s = s + str(x) + ' ' s s + str(x) + ' ' s + str(x) s str(x) str x ' ' print(s.rstrip()) print s.rstrip() s.rstrip s rstrip card card def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True is_stable i = 0 i 0 while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
     i < N i N if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
         get_card_suit(C1[i]) != get_card_suit(C2[i]) get_card_suit(C1[i]) get_card_suit C1[i] C1 i get_card_suit(C2[i]) get_card_suit C2[i] C2 i return False False i += 1 i 1 return True True bubble_sort(C1) bubble_sort C1 select_sort(C2) select_sort C2 output(C1) output C1 print('Stable') print 'Stable' output(C2) output C2 if is_stable() == True:
    print('Stable')
else:
    print('Not stable') is_stable() == True is_stable() is_stable True print('Stable') print 'Stable' print('Not stable') print 'Not stable' N = int(input()) int(input()) N C2 = C1[:] C1[:] C2 def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True is_stable def get_card_suit(card):
    return card[:1] def get_card_suit(card):
    return card[:1] get_card_suit def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip()) def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip()) output def get_card_value(card):
    return card[1:] def get_card_value(card):
    return card[1:] get_card_value def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1 def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1 bubble_sort C1 = list(input().split()) list(input().split()) C1 def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1 def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1 select_sort
N = int(input())
C1 = list(input().split()) 
C2 = C1[:]

def get_card_suit(card):
    return card[:1]

def get_card_value(card):
    return card[1:]

def bubble_sort(card):
    r_exists = True

    while r_exists == True:

        r_exists = False

        i = N - 1

        while i >= 1:

            if get_card_value(card[i]) < get_card_value(card[i - 1]):
                
                card[i], card[i - 1] = card[i - 1], card[i]

                r_exists = True
            
            i -= 1

def select_sort(card):
    i = 0

    while i < N:

        min_j = i
        j = i

        while j < N:

            if get_card_value(card[j]) < get_card_value(card[min_j]):

                min_j = j

            j += 1

        card[i], card[min_j] = card[min_j], card[i]

        i += 1

def output(card):
    s = ''

    for x in card:

        s = s + str(x) + ' '

    print(s.rstrip())

def is_stable():
    i = 0

    while i < N:
        if get_card_suit(C1[i]) != get_card_suit(C2[i]):
            return False
        i += 1
    
    return True

bubble_sort(C1)
select_sort(C2)

output(C1)
print('Stable')

output(C2)
if is_stable() == True:
    print('Stable')
else:
    print('Not stable')

