def bubbleSort(l, n):
    for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
    return l[:]

def selectionSort(l, n):
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
    return l[:]

n = int(input())
l = []
for c in input().split():
    l.append((int(c[1]), c[0]))
    
bl = ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)])
sl = ' '.join([k + str(n) for n, k in selectionSort(l[:], n)])
print(bl)
print('Stable')
print(sl)
print('Stable' if sl == bl else 'Not stable') def bubbleSort(l, n):
    for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
    return l[:] bubbleSort for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
     i range(n) range n for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
     j range(n-1-i) range n-1-i n-1 n 1 i if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
     l[j][0] > l[j+1][0] l[j][0] [j] l j 0 l[j+1][0] [j+1] l j+1 j 1 0 l[j], l[j+1] = l[j+1], l[j] l[j] l j l[j+1] l j+1 j 1 l[j+1] l j+1 j 1 l[j] l j return l[:] l[:] l : l l n n def selectionSort(l, n):
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
    return l[:] selectionSort for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
     i range(n) range n minj = i minj i for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
         j range(i+1, n) range i+1 i 1 n if l[j][0] < l[minj][0]:
                minj = j
         l[j][0] < l[minj][0] l[j][0] [j] l j 0 l[minj][0] [minj] l minj 0 minj = j minj j l[i], l[minj] = l[minj], l[i] l[i] l i l[minj] l minj l[minj] l minj l[i] l i return l[:] l[:] l : l l n n n = int(input()) n int(input()) int input() input l = [] l [] for c in input().split():
    l.append((int(c[1]), c[0]))
     c input().split() ().split () input split l.append((int(c[1]), c[0])) l.append l append (int(c[1]), c[0]) int(c[1]) int c[1] c 1 c[0] c 0 k + str(n) for n, k in bubbleSort(l[:], n) for n, k in bubbleSort(l[:], n) n k bubbleSort(l[:], n) bubbleSort l[:] l : n for n, k in bubbleSort(l[:], n) k + str(n) k str(n) str n bl = ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)]) bl ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)]) ' '.join ' ' join [k + str(n) for n, k in bubbleSort(l[:], n)] k + str(n) for n, k in selectionSort(l[:], n) for n, k in selectionSort(l[:], n) n k selectionSort(l[:], n) selectionSort l[:] l : n for n, k in selectionSort(l[:], n) k + str(n) k str(n) str n sl = ' '.join([k + str(n) for n, k in selectionSort(l[:], n)]) sl ' '.join([k + str(n) for n, k in selectionSort(l[:], n)]) ' '.join ' ' join [k + str(n) for n, k in selectionSort(l[:], n)] print(bl) print bl print('Stable') print 'Stable' print(sl) print sl print('Stable' if sl == bl else 'Not stable') print 'Stable' if sl == bl else 'Not stable' sl == bl sl bl 'Stable' 'Not stable' def selectionSort(l, n):
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
    return l[:] def selectionSort(l, n):
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
    return l[:] selectionSort def bubbleSort(l, n):
    for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
    return l[:] def bubbleSort(l, n):
    for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
    return l[:] bubbleSort sl = ' '.join([k + str(n) for n, k in selectionSort(l[:], n)]) ' '.join([k + str(n) for n, k in selectionSort(l[:], n)]) sl l = [] [] l bl = ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)]) ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)]) bl n = int(input()) int(input()) n
def bubbleSort(l, n):
    for i in range(n):
        for j in range(n-1-i):
            if l[j][0] > l[j+1][0]:
                l[j], l[j+1] = l[j+1], l[j]
    return l[:]

def selectionSort(l, n):
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if l[j][0] < l[minj][0]:
                minj = j
        l[i], l[minj] = l[minj], l[i]
    return l[:]

n = int(input())
l = []
for c in input().split():
    l.append((int(c[1]), c[0]))
    
bl = ' '.join([k + str(n) for n, k in bubbleSort(l[:], n)])
sl = ' '.join([k + str(n) for n, k in selectionSort(l[:], n)])
print(bl)
print('Stable')
print(sl)
print('Stable' if sl == bl else 'Not stable')