def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(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

def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True

n = int(input())
c = input().split(' ')
trump = [list(i) for i in c]
bubble = ["".join(s) for s in bubbleSort(trump, n)]
trump = [list(i) for i in c]
selection = ["".join(s) for s in selectionSort(trump, n)]
str_bubble = " ".join(bubble)
str_selection = " ".join(selection)
print(str_bubble)
print('Stable')
print(str_selection)
if isStable(bubble, selection, n):
    print('Stable')
else:
    print('Not stable')
 def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(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 reversed(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 reversed(range(1,n)):
            if(c[i][1] < c[i-1][1]):
                c[i], c[i-1] = c[i-1], c[i]
                flag = 1
     i reversed(range(1,n)) reversed 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 def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True isStable for i in range(n):
        if(c1[i] != c2[i]):
            return False
     i range(n) range n if(c1[i] != c2[i]):
            return False
     c1[i] != c2[i] c1[i] c1 i c2[i] c2 i return False False return True True c1 c1 c2 c2 n n n = int(input()) n int(input()) int input() input c = input().split(' ') c input().split(' ') ().split () input split ' ' list(i) for i in c for i in c i c for i in c list(i) list i trump = [list(i) for i in c] trump [list(i) for i in c] "".join(s) for s in bubbleSort(trump, n) for s in bubbleSort(trump, n) s bubbleSort(trump, n) bubbleSort trump n for s in bubbleSort(trump, n) "".join(s) "".join "" join s bubble = ["".join(s) for s in bubbleSort(trump, n)] bubble ["".join(s) for s in bubbleSort(trump, n)] list(i) for i in c for i in c i c for i in c list(i) list i trump = [list(i) for i in c] trump [list(i) for i in c] "".join(s) for s in selectionSort(trump, n) for s in selectionSort(trump, n) s selectionSort(trump, n) selectionSort trump n for s in selectionSort(trump, n) "".join(s) "".join "" join s selection = ["".join(s) for s in selectionSort(trump, n)] selection ["".join(s) for s in selectionSort(trump, n)] str_bubble = " ".join(bubble) str_bubble " ".join(bubble) " ".join " " join bubble str_selection = " ".join(selection) str_selection " ".join(selection) " ".join " " join selection print(str_bubble) print str_bubble print('Stable') print 'Stable' print(str_selection) print str_selection if isStable(bubble, selection, n):
    print('Stable')
else:
    print('Not stable') isStable(bubble, selection, n) isStable bubble selection n print('Stable') print 'Stable' print('Not stable') print 'Not stable' bubble = ["".join(s) for s in bubbleSort(trump, n)] ["".join(s) for s in bubbleSort(trump, n)] bubble str_selection = " ".join(selection) " ".join(selection) str_selection selection = ["".join(s) for s in selectionSort(trump, n)] ["".join(s) for s in selectionSort(trump, n)] selection trump = [list(i) for i in c] [list(i) for i in c] trump 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 trump = [list(i) for i in c] [list(i) for i in c] trump n = int(input()) int(input()) n def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(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 reversed(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 c = input().split(' ') input().split(' ') c str_bubble = " ".join(bubble) " ".join(bubble) str_bubble def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True isStable
def bubbleSort(c, n):
    flag = 1
    while(flag) :
        flag = 0
        for i in reversed(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

def isStable(c1, c2, n):
    for i in range(n):
        if(c1[i] != c2[i]):
            return False
    return True

n = int(input())
c = input().split(' ')
trump = [list(i) for i in c]
bubble = ["".join(s) for s in bubbleSort(trump, n)]
trump = [list(i) for i in c]
selection = ["".join(s) for s in selectionSort(trump, n)]
str_bubble = " ".join(bubble)
str_selection = " ".join(selection)
print(str_bubble)
print('Stable')
print(str_selection)
if isStable(bubble, selection, n):
    print('Stable')
else:
    print('Not stable')

