def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False

def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a

def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a

def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable"


n = int(raw_input())
cards = raw_input().split(' ')

sorted_cards = bubble_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards)
sorted_cards = selection_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards) def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False comp if a[1] > b[1]:
        return True
    else:
        return False a[1] > b[1] a[1] a 1 b[1] b 1 return True True return False False a a b b def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a bubble_sort for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
     i range(n) range n for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
     j reversed(range(i+1,n)) reversed range(i+1,n) range i+1 i 1 n if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
     comp(a[j-1],a[j]) comp a[j-1] a j-1 j 1 a[j] a j 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 a a def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a selection_sort for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
     i range(n) range n mini = i mini i for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
         j range(i,n) range i n if comp(a[mini],a[j]):
                mini=j
         comp(a[mini],a[j]) comp a[mini] a mini a[j] a j mini=j mini j a[mini],a[i]=a[i],a[mini] a[mini] a mini a[i] a i a[i] a i a[mini] a mini return a a a a def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable" stable for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
     num range(1,10) range 1 10 suite_ord = [] suite_ord [] for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
         v original_a if v[1] == str(num):
                suite_ord.append(v[0])
         v[1] == str(num) v[1] v 1 str(num) str num suite_ord.append(v[0]) suite_ord.append suite_ord append v[0] v 0 for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
     v sorted_a if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
     v[1] == str(num) v[1] v 1 str(num) str num if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
     v[0]==suite_ord[0] v[0] v 0 suite_ord[0] suite_ord 0 del suite_ord[0] suite_ord[0] suite_ord 0 return "Not stable" "Not stable" return "Stable" "Stable" original_a original_a sorted_a sorted_a n = int(raw_input()) n int(raw_input()) int raw_input() raw_input cards = raw_input().split(' ') cards raw_input().split(' ') ().split () raw_input split ' ' sorted_cards = bubble_sort(cards[:]) sorted_cards bubble_sort(cards[:]) bubble_sort cards[:] cards : print ' '.join(sorted_cards) ' '.join ' ' join sorted_cards print stable(cards,sorted_cards) stable cards sorted_cards sorted_cards = selection_sort(cards[:]) sorted_cards selection_sort(cards[:]) selection_sort cards[:] cards : print ' '.join(sorted_cards) ' '.join ' ' join sorted_cards print stable(cards,sorted_cards) stable cards sorted_cards cards = raw_input().split(' ') raw_input().split(' ') cards sorted_cards = bubble_sort(cards[:]) bubble_sort(cards[:]) sorted_cards def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable" def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable" stable n = int(raw_input()) int(raw_input()) n sorted_cards = selection_sort(cards[:]) selection_sort(cards[:]) sorted_cards def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a bubble_sort def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False comp def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a selection_sort
def comp(a,b):
    if a[1] > b[1]:
        return True
    else:
        return False

def bubble_sort(a):
    for i in range(n):
        for j in reversed(range(i+1,n)):
            if comp(a[j-1],a[j]):
                a[j],a[j-1]=a[j-1],a[j]
    return a

def selection_sort(a):
    for i in range(n):
        mini = i
        for j in range(i,n):
            if comp(a[mini],a[j]):
                mini=j
        a[mini],a[i]=a[i],a[mini]
    return a

def stable(original_a,sorted_a):
    for num in range(1,10):
        suite_ord = []
        for v in original_a:
            if v[1] == str(num):
                suite_ord.append(v[0])
        for v in sorted_a:
            if v[1] == str(num):
                if v[0]==suite_ord[0]:
                    del suite_ord[0]
                else:
                    return "Not stable"
    return "Stable"


n = int(raw_input())
cards = raw_input().split(' ')

sorted_cards = bubble_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards)
sorted_cards = selection_sort(cards[:])
print ' '.join(sorted_cards)
print stable(cards,sorted_cards)