class Card(object):
    def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
    def __str__(self):
        return self.suit + str(self.value)

def is_stable(bs, ss):
    if bs == ss:
        return 'Stable'
    else:
        return 'Not stable'

def bubble_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
    return c

def selection_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
    return c

n = input()
nums = input()

bs = bubble_sort(nums, int(n))
bs_str = [str(card) for card in bs]
print(' '.join(bs_str))
print('Stable')

ss = selection_sort(nums, int(n))
ss_str = [str(card) for card in ss]
print(' '.join(ss_str))
print(is_stable(bs_str, ss_str)) class Card(object):
    def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
    def __str__(self):
        return self.suit + str(self.value) Card def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
     __init__ self.suit = card[:1] self.suit self suit card[:1] card :1 1 self.value = int(card[1:]) self.value self value int(card[1:]) int card[1:] card 1: 1 self self card card def __str__(self):
        return self.suit + str(self.value) __str__ return self.suit + str(self.value) self.suit + str(self.value) self.suit self suit str(self.value) str self.value self value self self object def is_stable(bs, ss):
    if bs == ss:
        return 'Stable'
    else:
        return 'Not stable' is_stable if bs == ss:
        return 'Stable'
    else:
        return 'Not stable' bs == ss bs ss return 'Stable' 'Stable' return 'Not stable' 'Not stable' bs bs ss ss def bubble_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
    return c bubble_sort c = c.split() c c.split() c.split c split Card(card) for card in c for card in c card c for card in c Card(card) Card card c = [Card(card) for card in c] c [Card(card) for card in c] for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
     i range(n-1) range n-1 n 1 for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
     j range(n-1) range n-1 n 1 if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
     c[j].value > c[j+1].value c[j].value [j] c j value c[j+1].value [j+1] c j+1 j 1 value c[j], c[j+1] = c[j+1], c[j] c[j] c j c[j+1] c j+1 j 1 c[j+1] c j+1 j 1 c[j] c j return c c c c n n def selection_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
    return c selection_sort c = c.split() c c.split() c.split c split Card(card) for card in c for card in c card c for card in c Card(card) Card card c = [Card(card) for card in c] c [Card(card) for card in c] for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
     i range(n) range n mink = i mink i for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
         v range(i, n) range i n if c[v].value < c[mink].value:
                mink = v
         c[v].value < c[mink].value c[v].value [v] c v value c[mink].value [mink] c mink value mink = v mink v if mink != i:
            c[i], c[mink] = c[mink], c[i]
     mink != i mink i c[i], c[mink] = c[mink], c[i] c[i] c i c[mink] c mink c[mink] c mink c[i] c i return c c c c n n n = input() n input() input nums = input() nums input() input bs = bubble_sort(nums, int(n)) bs bubble_sort(nums, int(n)) bubble_sort nums int(n) int n str(card) for card in bs for card in bs card bs for card in bs str(card) str card bs_str = [str(card) for card in bs] bs_str [str(card) for card in bs] print(' '.join(bs_str)) print ' '.join(bs_str) ' '.join ' ' join bs_str print('Stable') print 'Stable' ss = selection_sort(nums, int(n)) ss selection_sort(nums, int(n)) selection_sort nums int(n) int n str(card) for card in ss for card in ss card ss for card in ss str(card) str card ss_str = [str(card) for card in ss] ss_str [str(card) for card in ss] print(' '.join(ss_str)) print ' '.join(ss_str) ' '.join ' ' join ss_str print(is_stable(bs_str, ss_str)) print is_stable(bs_str, ss_str) is_stable bs_str ss_str def bubble_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
    return c def bubble_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
    return c bubble_sort nums = input() input() nums bs_str = [str(card) for card in bs] [str(card) for card in bs] bs_str def is_stable(bs, ss):
    if bs == ss:
        return 'Stable'
    else:
        return 'Not stable' def is_stable(bs, ss):
    if bs == ss:
        return 'Stable'
    else:
        return 'Not stable' is_stable bs = bubble_sort(nums, int(n)) bubble_sort(nums, int(n)) bs class Card(object):
    def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
    def __str__(self):
        return self.suit + str(self.value) class Card(object):
    def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
    def __str__(self):
        return self.suit + str(self.value) Card ss_str = [str(card) for card in ss] [str(card) for card in ss] ss_str def selection_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
    return c def selection_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
    return c selection_sort ss = selection_sort(nums, int(n)) selection_sort(nums, int(n)) ss n = input() input() n
class Card(object):
    def __init__(self, card):
        self.suit = card[:1]
        self.value = int(card[1:])
    
    def __str__(self):
        return self.suit + str(self.value)

def is_stable(bs, ss):
    if bs == ss:
        return 'Stable'
    else:
        return 'Not stable'

def bubble_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n-1):
        for j in range(n-1):
            if c[j].value > c[j+1].value:
                c[j], c[j+1] = c[j+1], c[j]
    return c

def selection_sort(c, n):
    c = c.split()
    c = [Card(card) for card in c]
    for i in range(n):
        mink = i
        for v in range(i, n):
            if c[v].value < c[mink].value:
                mink = v
        if mink != i:
            c[i], c[mink] = c[mink], c[i]
    return c

n = input()
nums = input()

bs = bubble_sort(nums, int(n))
bs_str = [str(card) for card in bs]
print(' '.join(bs_str))
print('Stable')

ss = selection_sort(nums, int(n))
ss_str = [str(card) for card in ss]
print(' '.join(ss_str))
print(is_stable(bs_str, ss_str))
