class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number)


def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls)


def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls)

def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable')


_ = int(input())
l2 =  [Card(i) for i in input().split()]
l2_sort = sorted(l2)

bubble = BubbleSort(l2)
judge(l2_sort, bubble)

select = SelectSort(l2)
judge(l2_sort, select)
 class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number) Card def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
     __init__ self.card = card self.card self card card self.mark = card[0] self.mark self mark card[0] card 0 self.number = card[1] self.number self number card[1] card 1 self self card card def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
     __lt__ if not isinstance(other, Card):
            return NotImplemented
         not isinstance(other, Card) isinstance(other, Card) isinstance other Card return NotImplemented NotImplemented return self.number < other.number self.number < other.number self.number self number other.number other number self self other other def __repr__(self):
        return '{}{}'.format(self.mark, self.number) __repr__ return '{}{}'.format(self.mark, self.number) '{}{}'.format(self.mark, self.number) '{}{}'.format '{}{}' format self.mark self mark self.number self number self self def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls) BubbleSort ls = target.copy() ls target.copy() target.copy target copy flag = 1 flag 1 while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
     flag flag = 0 flag 0 for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
     i range(len(ls)-1, 0, -1) range len(ls)-1 len(ls) len ls 1 0 -1 if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
     ls[i] < ls[i-1] ls[i] ls i ls[i-1] ls i-1 i 1 ls[i], ls[i-1] = ls[i-1], ls[i] ls[i] ls i ls[i-1] ls i-1 i 1 ls[i-1] ls i-1 i 1 ls[i] ls i flag = 1 flag 1 print(' '.join(map(str, ls))) print ' '.join(map(str, ls)) ' '.join ' ' join map(str, ls) map str ls return sorted(ls) sorted(ls) sorted ls target target def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls) SelectSort ls = target.copy() ls target.copy() target.copy target copy for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
     i range(len(ls)) range len(ls) len ls minj = i minj i for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
         j range(i+1, len(ls)) range i+1 i 1 len(ls) len ls if ls[j] < ls[minj]:
                minj = j
         ls[j] < ls[minj] ls[j] ls j ls[minj] ls minj minj = j minj j if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
     ls[i] != ls[minj] ls[i] ls i ls[minj] ls minj ls[i], ls[minj] = ls[minj], ls[i] ls[i] ls i ls[minj] ls minj ls[minj] ls minj ls[i] ls i print(' '.join(map(str, ls))) print ' '.join(map(str, ls)) ' '.join ' ' join map(str, ls) map str ls return sorted(ls) sorted(ls) sorted ls target target def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable') judge if original == sorted_list:
        print('Stable')
    else:
        print('Not stable') original == sorted_list original sorted_list print('Stable') print 'Stable' print('Not stable') print 'Not stable' original original sorted_list sorted_list _ = int(input()) _ int(input()) int input() input Card(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() Card(i) Card i l2 =  [Card(i) for i in input().split()] l2 [Card(i) for i in input().split()] l2_sort = sorted(l2) l2_sort sorted(l2) sorted l2 bubble = BubbleSort(l2) bubble BubbleSort(l2) BubbleSort l2 judge(l2_sort, bubble) judge l2_sort bubble select = SelectSort(l2) select SelectSort(l2) SelectSort l2 judge(l2_sort, select) judge l2_sort select _ = int(input()) int(input()) _ def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable') def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable') judge select = SelectSort(l2) SelectSort(l2) select l2 =  [Card(i) for i in input().split()] [Card(i) for i in input().split()] l2 bubble = BubbleSort(l2) BubbleSort(l2) bubble l2_sort = sorted(l2) sorted(l2) l2_sort def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls) def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls) BubbleSort class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number) class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number) Card def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls) def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls) SelectSort
class Card():
    def __init__(self, card):
        self.card = card
        self.mark = card[0]
        self.number = card[1]
        
    def __lt__(self, other):
        if not isinstance(other, Card):
            return NotImplemented
        return self.number < other.number
        
    def __repr__(self):
        return '{}{}'.format(self.mark, self.number)


def BubbleSort(target):
    ls = target.copy()
    flag = 1
    while flag:
        flag = 0
        for i in range(len(ls)-1, 0, -1):
            if ls[i] < ls[i-1]:
                ls[i], ls[i-1] = ls[i-1], ls[i]
                flag = 1
    print(' '.join(map(str, ls)))
    return sorted(ls)


def SelectSort(target):
    ls = target.copy()
    for i in range(len(ls)):
        minj = i
        for j in range(i+1, len(ls)):
            if ls[j] < ls[minj]:
                minj = j
        if ls[i] != ls[minj]:
            ls[i], ls[minj] = ls[minj], ls[i]
    
    print(' '.join(map(str, ls)))
    return sorted(ls)

def judge(original, sorted_list):
    if original == sorted_list:
        print('Stable')
    else:
        print('Not stable')


_ = int(input())
l2 =  [Card(i) for i in input().split()]
l2_sort = sorted(l2)

bubble = BubbleSort(l2)
judge(l2_sort, bubble)

select = SelectSort(l2)
judge(l2_sort, select)

