import copy
def bs(array):
    for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
    return array
def ss(array):
    for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
    return array
def isStable(ar1,ar2):
    flag = 0
    for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
    if flag == 0:
        print('Stable')
    else:
        print('Not stable')


n = input()
arr = [[i[0],int(i[1])] for i in input().split()]
arr1 = copy.deepcopy(arr)
arr2 = copy.deepcopy(arr)

bsarr = bs(arr2)
ssarr = ss(arr1)
print(' '.join([''.join([ x[0], str(x[1]) ]) for x in bsarr]))
print('Stable')
print(' '.join([''.join([ x[0], str(x[1]) ]) for x in ssarr]))
isStable(bsarr,ssarr) import copy copy def bs(array):
    for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
    return array bs for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
     i range(len(array)-1) range len(array)-1 len(array) len array 1 for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
     c range(len(array)-1, i,-1) range len(array)-1 len(array) len array 1 i -1 if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
     array[c][1] < array[c-1][1] array[c][1] [c] array c 1 array[c-1][1] [c-1] array c-1 c 1 1 swap = array[c] swap array[c] array c array[c] = array[c-1] array[c] array c array[c-1] array c-1 c 1 array[c-1] = swap array[c-1] array c-1 c 1 swap return array array array array def ss(array):
    for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
    return array ss for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
     i range(len(array)) range len(array) len array minj = i minj i for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
         c range(i+1,len(array)) range i+1 i 1 len(array) len array if array[minj][1] > array[c][1]:
                minj = c
         array[minj][1] > array[c][1] array[minj][1] [minj] array minj 1 array[c][1] [c] array c 1 minj = c minj c swap = array[i] swap array[i] array i array[i] = array[minj] array[i] array i array[minj] array minj array[minj] = swap array[minj] array minj swap return array array array array def isStable(ar1,ar2):
    flag = 0
    for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
    if flag == 0:
        print('Stable')
    else:
        print('Not stable') isStable flag = 0 flag 0 for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
     (x,y) x y zip(ar1,ar2) zip ar1 ar2 if x != y:
            flag = 1
            break
     x != y x y flag = 1 flag 1 break if flag == 0:
        print('Stable')
    else:
        print('Not stable') flag == 0 flag 0 print('Stable') print 'Stable' print('Not stable') print 'Not stable' ar1 ar1 ar2 ar2 n = input() n input() input [i[0],int(i[1])] for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() [i[0],int(i[1])] i[0] i 0 int(i[1]) int i[1] i 1 arr = [[i[0],int(i[1])] for i in input().split()] arr [[i[0],int(i[1])] for i in input().split()] arr1 = copy.deepcopy(arr) arr1 copy.deepcopy(arr) copy.deepcopy copy deepcopy arr arr2 = copy.deepcopy(arr) arr2 copy.deepcopy(arr) copy.deepcopy copy deepcopy arr bsarr = bs(arr2) bsarr bs(arr2) bs arr2 ssarr = ss(arr1) ssarr ss(arr1) ss arr1 ''.join([ x[0], str(x[1]) ]) for x in bsarr for x in bsarr x bsarr for x in bsarr ''.join([ x[0], str(x[1]) ]) ''.join '' join [ x[0], str(x[1]) ] x[0] x 0 str(x[1]) str x[1] x 1 print(' '.join([''.join([ x[0], str(x[1]) ]) for x in bsarr])) print ' '.join([''.join([ x[0], str(x[1]) ]) for x in bsarr]) ' '.join ' ' join [''.join([ x[0], str(x[1]) ]) for x in bsarr] print('Stable') print 'Stable' ''.join([ x[0], str(x[1]) ]) for x in ssarr for x in ssarr x ssarr for x in ssarr ''.join([ x[0], str(x[1]) ]) ''.join '' join [ x[0], str(x[1]) ] x[0] x 0 str(x[1]) str x[1] x 1 print(' '.join([''.join([ x[0], str(x[1]) ]) for x in ssarr])) print ' '.join([''.join([ x[0], str(x[1]) ]) for x in ssarr]) ' '.join ' ' join [''.join([ x[0], str(x[1]) ]) for x in ssarr] isStable(bsarr,ssarr) isStable bsarr ssarr def ss(array):
    for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
    return array def ss(array):
    for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
    return array ss n = input() input() n arr = [[i[0],int(i[1])] for i in input().split()] [[i[0],int(i[1])] for i in input().split()] arr arr1 = copy.deepcopy(arr) copy.deepcopy(arr) arr1 def isStable(ar1,ar2):
    flag = 0
    for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
    if flag == 0:
        print('Stable')
    else:
        print('Not stable') def isStable(ar1,ar2):
    flag = 0
    for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
    if flag == 0:
        print('Stable')
    else:
        print('Not stable') isStable arr2 = copy.deepcopy(arr) copy.deepcopy(arr) arr2 bsarr = bs(arr2) bs(arr2) bsarr ssarr = ss(arr1) ss(arr1) ssarr def bs(array):
    for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
    return array def bs(array):
    for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
    return array bs
import copy
def bs(array):
    for i in range(len(array)-1):
        for c in range(len(array)-1, i,-1):
            if array[c][1] < array[c-1][1]:
                swap = array[c]
                array[c] = array[c-1]
                array[c-1] = swap
    return array
def ss(array):
    for i in range(len(array)):
        minj = i
        for c in range(i+1,len(array)):
            if array[minj][1] > array[c][1]:
                minj = c
        swap = array[i]
        array[i] = array[minj]
        array[minj] = swap
    return array
def isStable(ar1,ar2):
    flag = 0
    for (x,y) in zip(ar1,ar2):
        if x != y:
            flag = 1
            break
    if flag == 0:
        print('Stable')
    else:
        print('Not stable')


n = input()
arr = [[i[0],int(i[1])] for i in input().split()]
arr1 = copy.deepcopy(arr)
arr2 = copy.deepcopy(arr)

bsarr = bs(arr2)
ssarr = ss(arr1)
print(' '.join([''.join([ x[0], str(x[1]) ]) for x in bsarr]))
print('Stable')
print(' '.join([''.join([ x[0], str(x[1]) ]) for x in ssarr]))
isStable(bsarr,ssarr)