#!/usr/bin/env python
#-*- coding: utf-8 -*-


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


def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass


if __name__ == '__main__':
    N = raw_input()
    l1 = raw_input().split()
    l2 = l1[:]
    bubble_sort(l1)
    print ' '.join(l1)
    print "Stable"
    selection_sort(l2)
    print ' '.join(l2)
    if l1 == l2:
        print "Stable"
    else:
        print "Not stable" def selection_sort(l):
    N = len(l)
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i] selection_sort N = len(l) N len(l) len l for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i] i range(0, N) range 0 N minj = i minj i for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
         j range(i, N) range i N 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 if i != minj:
            l[i], l[minj] = l[minj], l[i] i != minj i minj l[i], l[minj] = l[minj], l[i] l[i] l i l[minj] l minj l[minj] l minj l[i] l i l l def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass bubble_sort N = len(l) N len(l) len l for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
     i range(0, N) range 0 N for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
     j range(N - 1, i, -1) range N - 1 N 1 i -1 if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
     int(l[j][1]) < int(l[j - 1][1]) int(l[j][1]) int l[j][1] [j] l j 1 int(l[j - 1][1]) int l[j - 1][1] [j - 1] l j - 1 j 1 1 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 l l if __name__ == '__main__':
    N = raw_input()
    l1 = raw_input().split()
    l2 = l1[:]
    bubble_sort(l1)
    print ' '.join(l1)
    print "Stable"
    selection_sort(l2)
    print ' '.join(l2)
    if l1 == l2:
        print "Stable"
    else:
        print "Not stable" __name__ == '__main__' __name__ '__main__' N = raw_input() N raw_input() raw_input l1 = raw_input().split() l1 raw_input().split() ().split () raw_input split l2 = l1[:] l2 l1[:] l1 : bubble_sort(l1) bubble_sort l1 print ' '.join(l1) ' '.join ' ' join l1 print selection_sort(l2) selection_sort l2 print ' '.join(l2) ' '.join ' ' join l2 if l1 == l2:
        print "Stable"
    else:
        print "Not stable" l1 == l2 l1 l2 print print l1 = raw_input().split() raw_input().split() l1 l2 = l1[:] l1[:] l2 def selection_sort(l):
    N = len(l)
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i] def selection_sort(l):
    N = len(l)
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if int(l[j][1]) < int(l[minj][1]):
                minj = j
        if i != minj:
            l[i], l[minj] = l[minj], l[i] selection_sort def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass bubble_sort N = raw_input() raw_input() N
#!/usr/bin/env python
#-*- coding: utf-8 -*-


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


def bubble_sort(l):
    N = len(l)
    for i in range(0, N):
        for j in range(N - 1, i, -1):
            if int(l[j][1]) < int(l[j - 1][1]):
                l[j], l[j - 1] = l[j - 1], l[j]
    pass


if __name__ == '__main__':
    N = raw_input()
    l1 = raw_input().split()
    l2 = l1[:]
    bubble_sort(l1)
    print ' '.join(l1)
    print "Stable"
    selection_sort(l2)
    print ' '.join(l2)
    if l1 == l2:
        print "Stable"
    else:
        print "Not stable"
