def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return



def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return


def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    cards = [x for x in input().split(' ')]
    #cards = ['H4', 'C9', 'S4', 'D2', 'C3']
    #cards = ['S1', 'H1']
    t = cards[:]  # ???????????????
    u = cards[:]

    # ???????????????????????????
    do_bubble_sort(t, len(t))
    do_selection_sort(u, len(u))
    result = is_stable(t, u)

    # ???????????????
    print('{0}'.format(' '.join(map(str, t))))
    print('Stable')
    print('{0}'.format(' '.join(map(str, u))))
    if result is True:
        print('Stable')
    else:
        print('Not stable') def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return do_bubble_sort """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """ flag = True flag True i = 0 i 0 while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
     flag is True flag True flag = False flag False for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
         j range(n-1, i, -1) range n-1 n 1 i -1 dj = int(data[j][1]) dj int(data[j][1]) int data[j][1] [j] data j 1 dj_1 = int(data[j-1][1]) dj_1 int(data[j-1][1]) int data[j-1][1] [j-1] data j-1 j 1 1 if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
         dj < dj_1 dj dj_1 temp = data[j] temp data[j] data j data[j] = data[j-1] data[j] data j data[j-1] data j-1 j 1 data[j-1] = temp data[j-1] data j-1 j 1 temp flag = True flag True i == 1 i 1 return data data n n def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return do_selection_sort assert size == len(data), "data size error" size == len(data) size len(data) len data "data size error" for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
     i range(size) range size minj = i minj i for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
         j range(i, size) range i size dj = int(data[j][1]) dj int(data[j][1]) int data[j][1] [j] data j 1 dmin = int(data[minj][1]) dmin int(data[minj][1]) int data[minj][1] [minj] data minj 1 if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
         dj < dmin dj dmin minj = j minj j temp = data[i] temp data[i] data i data[i] = data[minj] data[i] data i data[minj] data minj data[minj] = temp data[minj] data minj temp return data data size size def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True is_stable for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
     b s zip(bubble_d, selection_d) zip bubble_d selection_d if b != s:
            return False
     b != s b s return False False return True True bubble_d bubble_d selection_d selection_d if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    cards = [x for x in input().split(' ')]
    #cards = ['H4', 'C9', 'S4', 'D2', 'C3']
    #cards = ['S1', 'H1']
    t = cards[:]  # ???????????????
    u = cards[:]

    # ???????????????????????????
    do_bubble_sort(t, len(t))
    do_selection_sort(u, len(u))
    result = is_stable(t, u)

    # ???????????????
    print('{0}'.format(' '.join(map(str, t))))
    print('Stable')
    print('{0}'.format(' '.join(map(str, u))))
    if result is True:
        print('Stable')
    else:
        print('Not stable') __name__ == '__main__' __name__ '__main__' num = int(input()) num int(input()) int input() input x for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') x cards = [x for x in input().split(' ')] cards [x for x in input().split(' ')] t = cards[:] t cards[:] cards : u = cards[:] u cards[:] cards : do_bubble_sort(t, len(t)) do_bubble_sort t len(t) len t do_selection_sort(u, len(u)) do_selection_sort u len(u) len u result = is_stable(t, u) result is_stable(t, u) is_stable t u print('{0}'.format(' '.join(map(str, t)))) print '{0}'.format(' '.join(map(str, t))) '{0}'.format '{0}' format ' '.join(map(str, t)) ' '.join ' ' join map(str, t) map str t print('Stable') print 'Stable' print('{0}'.format(' '.join(map(str, u)))) print '{0}'.format(' '.join(map(str, u))) '{0}'.format '{0}' format ' '.join(map(str, u)) ' '.join ' ' join map(str, u) map str u if result is True:
        print('Stable')
    else:
        print('Not stable') result is True result True print('Stable') print 'Stable' print('Not stable') print 'Not stable' t = cards[:] cards[:] t cards = [x for x in input().split(' ')] [x for x in input().split(' ')] cards def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return do_selection_sort def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return do_bubble_sort u = cards[:] cards[:] u result = is_stable(t, u) is_stable(t, u) result def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True is_stable num = int(input()) int(input()) num
def do_bubble_sort(data, n):
    """ ??°???data??????????????????????????????????????§???????????????????????????n?????°????????????
    ?????????????????????????????°??¨????????????????????????????????????
    """
    flag = True
    i = 0
    while flag is True:
        flag = False
        for j in range(n-1, i, -1):
            dj = int(data[j][1])
            dj_1 = int(data[j-1][1])
            #if data[j] < data[j-1]:
            if dj < dj_1:
                temp = data[j]
                data[j] = data[j-1]
                data[j-1] = temp
                flag = True
        i == 1
    return



def do_selection_sort(data, size):
    assert size == len(data), "data size error"
    for i in range(size):
        minj = i
        for j in range(i, size):
            dj = int(data[j][1])
            dmin = int(data[minj][1])
            if dj < dmin:
            #if data[j] < data[minj]:
                minj = j
        temp = data[i]
        data[i] = data[minj]
        data[minj] = temp
    return


def is_stable(bubble_d, selection_d):
    for b, s in zip(bubble_d, selection_d):
        if b != s:
            return False
    return True


if __name__ == '__main__':
    # ??????????????\???
    num = int(input())
    cards = [x for x in input().split(' ')]
    #cards = ['H4', 'C9', 'S4', 'D2', 'C3']
    #cards = ['S1', 'H1']
    t = cards[:]  # ???????????????
    u = cards[:]

    # ???????????????????????????
    do_bubble_sort(t, len(t))
    do_selection_sort(u, len(u))
    result = is_stable(t, u)

    # ???????????????
    print('{0}'.format(' '.join(map(str, t))))
    print('Stable')
    print('{0}'.format(' '.join(map(str, u))))
    if result is True:
        print('Stable')
    else:
        print('Not stable')