def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable')

def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c

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

main() def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable') main N = int(input()) N int(input()) int input() input CARD = tuple(input().split()) CARD tuple(input().split()) tuple input().split() ().split () input split sort_ = [] sort_ [] for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

     i range(1, 10) range 1 10 for s in CARD:
            if str(i) in s:
                sort_.append(s)

     s CARD if str(i) in s:
                sort_.append(s)

     str(i) in s str(i) str i s sort_.append(s) sort_.append sort_ append s sort_ = tuple(sort_) sort_ tuple(sort_) tuple sort_ bsort = tuple(bubbleSort(list(CARD), N)) bsort tuple(bubbleSort(list(CARD), N)) tuple bubbleSort(list(CARD), N) bubbleSort list(CARD) list CARD N ssort = tuple(selectionSort(list(CARD), N)) ssort tuple(selectionSort(list(CARD), N)) tuple selectionSort(list(CARD), N) selectionSort list(CARD) list CARD N for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable') s (bsort, ssort) bsort ssort print(*s, sep=' ') print *s s sep=' ' sep ' ' if s == sort_:
            print('Stable')
        else:
            print('Not stable') s == sort_ s sort_ print('Stable') print 'Stable' print('Not stable') print 'Not stable' def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c bubbleSort flag = 1 flag 1 while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
     flag flag = 0 flag 0 for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
     i range(1, n) range 1 n if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
     c[i][1] < c[i-1][1] c[i][1] [i] c i 1 c[i-1][1] [i-1] c i-1 i 1 1 c[i], c[i-1] = c[i-1], c[i] c[i] c i c[i-1] c i-1 i 1 c[i-1] c i-1 i 1 c[i] c i flag = 1 flag 1 return c c c c n n def selectionSort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c selectionSort for i in range(n):
        minj = i
        for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
     i range(n) range n minj = i minj i for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj = j
         j range(i, n) range i n if c[j][1] < c[minj][1]:
                minj = j
         c[j][1] < c[minj][1] c[j][1] [j] c j 1 c[minj][1] [minj] c minj 1 minj = j minj j c[i], c[minj] = c[minj], c[i] c[i] c i c[minj] c minj c[minj] c minj c[i] c i return c c c c n n main() main def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable') def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable') main def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c bubbleSort def selectionSort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c def selectionSort(c, n):
    for i in range(n):
        minj = i
        for j in range(i, n):
            if c[j][1] < c[minj][1]:
                minj = j
        c[i], c[minj] = c[minj], c[i]
    return c selectionSort
def main():
    N = int(input())
    CARD = tuple(input().split())

    sort_ = []
    for i in range(1, 10):
        for s in CARD:
            if str(i) in s:
                sort_.append(s)

    sort_ = tuple(sort_)
    bsort = tuple(bubbleSort(list(CARD), N))
    ssort = tuple(selectionSort(list(CARD), N))

    for s in (bsort, ssort):
        print(*s, sep=' ')
        if s == sort_:
            print('Stable')
        else:
            print('Not stable')

def bubbleSort(c, n):
    flag = 1
    while flag:
        flag = 0
        for i in range(1, n):
            if c[i][1] < c[i-1][1]:
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
    return c

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

main()