n = int(input())

A = list(input().split())

def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l


def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l

def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True

def print_with_space(l):
    print(' '.join(str(x) for x in l))

B = insertion_sort(A[:])

babbled = babble_sort(A[:])
print_with_space(babbled)

if is_stable(B, babbled):
    print('Stable')
else:
    print('Not stable')

def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l

selected = selection_sort(A[:])
print_with_space(selected)

if is_stable(B, selected):
    print('Stable')
else:
    print('Not stable') n = int(input()) n int(input()) int input() input A = list(input().split()) A list(input().split()) list input().split() ().split () input split def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l insertion_sort for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
     i range(0, len(l) - 1) range 0 len(l) - 1 len(l) len l 1 x = i + 1 x i + 1 i 1 while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
     x != 0 and int(l[x][1]) < int(l[x - 1][1]) x != 0 x 0 int(l[x][1]) < int(l[x - 1][1]) int(l[x][1]) int l[x][1] [x] l x 1 int(l[x - 1][1]) int l[x - 1][1] [x - 1] l x - 1 x 1 1 temp = l[x] temp l[x] l x l[x] = l[x - 1] l[x] l x l[x - 1] l x - 1 x 1 l[x - 1] = temp l[x - 1] l x - 1 x 1 temp x -= 1 x 1 return l l l l def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l babble_sort for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
     i range(0, len(l)) range 0 len(l) len l for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
     j reversed(range(i+1, len(l))) reversed range(i+1, len(l)) range i+1 i 1 len(l) len l b = int(l[j][1]) b int(l[j][1]) int l[j][1] [j] l j 1 a = int(l[j - 1][1]) a int(l[j - 1][1]) int l[j - 1][1] [j - 1] l j - 1 j 1 1 if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
     b < a b a t = l[j] t l[j] l j l[j] = l[j-1] l[j] l j l[j-1] l j-1 j 1 l[j-1] = t l[j-1] l j-1 j 1 t return l l l l def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True is_stable for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
     i range(0, len(a)) range 0 len(a) len a if a[i] != l[i]:
            return False
     a[i] != l[i] a[i] a i l[i] l i return False False return True True a a l l def print_with_space(l):
    print(' '.join(str(x) for x in l)) print_with_space print(' '.join(str(x) for x in l)) print ' '.join(str(x) for x in l) ' '.join ' ' join str(x) str x l l B = insertion_sort(A[:]) B insertion_sort(A[:]) insertion_sort A[:] A : babbled = babble_sort(A[:]) babbled babble_sort(A[:]) babble_sort A[:] A : print_with_space(babbled) print_with_space babbled if is_stable(B, babbled):
    print('Stable')
else:
    print('Not stable') is_stable(B, babbled) is_stable B babbled print('Stable') print 'Stable' print('Not stable') print 'Not stable' def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l selection_sort for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
     i range(0, len(l)) range 0 len(l) len l minj = i minj i for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
         j range(i, len(l)) range i len(l) len l if int(l[j][1]) < int(l[minj][1]):
                minj = j
         int(l[j][1]) < int(l[minj][1]) int(l[j][1]) int l[j][1] [j] l j 1 int(l[minj][1]) int l[minj][1] [minj] l minj 1 minj = j minj j t = l[i] t l[i] l i l[i] = l[minj] l[i] l i l[minj] l minj l[minj] = t l[minj] l minj t return l l l l selected = selection_sort(A[:]) selected selection_sort(A[:]) selection_sort A[:] A : print_with_space(selected) print_with_space selected if is_stable(B, selected):
    print('Stable')
else:
    print('Not stable') is_stable(B, selected) is_stable B selected print('Stable') print 'Stable' print('Not stable') print 'Not stable' n = int(input()) int(input()) n B = insertion_sort(A[:]) insertion_sort(A[:]) B selected = selection_sort(A[:]) selection_sort(A[:]) selected babbled = babble_sort(A[:]) babble_sort(A[:]) babbled def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l selection_sort def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l babble_sort def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True is_stable def print_with_space(l):
    print(' '.join(str(x) for x in l)) def print_with_space(l):
    print(' '.join(str(x) for x in l)) print_with_space def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l insertion_sort A = list(input().split()) list(input().split()) A
n = int(input())

A = list(input().split())

def insertion_sort(l):
    for i in range(0, len(l) - 1):
        x = i + 1
        while x != 0 and int(l[x][1]) < int(l[x - 1][1]):
            temp = l[x]
            l[x] = l[x - 1]
            l[x - 1] = temp
            x -= 1
    return l


def babble_sort(l):
    for i in range(0, len(l)):
        for j in reversed(range(i+1, len(l))):
            b = int(l[j][1])
            a = int(l[j - 1][1])
            if b < a:
                t = l[j]
                l[j] = l[j-1]
                l[j-1] = t
    return l

def is_stable(a, l):
    for i in range(0, len(a)):
        if a[i] != l[i]:
            return False
    return True

def print_with_space(l):
    print(' '.join(str(x) for x in l))

B = insertion_sort(A[:])

babbled = babble_sort(A[:])
print_with_space(babbled)

if is_stable(B, babbled):
    print('Stable')
else:
    print('Not stable')

def selection_sort(l):
    for i in range(0, len(l)):
        minj = i
        for j in range(i, len(l)):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        t = l[i]
        l[i] = l[minj]
        l[minj] = t
    return l

selected = selection_sort(A[:])
print_with_space(selected)

if is_stable(B, selected):
    print('Stable')
else:
    print('Not stable')