def bubble_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
    for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C


def selection_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

    for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C


N = int(input().rstrip())
C = input().rstrip().split()

C_b = bubble_sort(C, N)
C_s = selection_sort(C, N)

print(' '.join(C_b))
print('Stable')

print(' '.join(C_s))
if C_s == C_b:
    print('Stable')
else:
    print('Not stable') def bubble_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
    for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C bubble_sort card = [] card [] for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
     c C card.append({'suit': c[0], 'value': int(c[1])}) card.append card append {'suit': c[0], 'value': int(c[1])} 'suit' 'suit' c[0] c 0 'value' 'value' int(c[1]) int c[1] c 1 for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

     i range(N) range N for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

     j range(N-1, i, -1) range N-1 N 1 i -1 if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

     card[j]['value'] < card[j-1]['value'] card[j]['value'] [j] card j 'value' card[j-1]['value'] [j-1] card j-1 j 1 'value' card[j], card[j-1] = card[j-1], card[j] card[j] card j card[j-1] card j-1 j 1 card[j-1] card j-1 j 1 card[j] card j new_C = [] new_C [] for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
     i range(N) range N new_C.append(card[i]['suit'] + str(card[i]['value'])) new_C.append new_C append card[i]['suit'] + str(card[i]['value']) card[i]['suit'] [i] card i 'suit' str(card[i]['value']) str card[i]['value'] [i] card i 'value' return new_C new_C C C N N def selection_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

    for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C selection_sort card = [] card [] for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

     c C card.append({'suit': c[0], 'value': int(c[1])}) card.append card append {'suit': c[0], 'value': int(c[1])} 'suit' 'suit' c[0] c 0 'value' 'value' int(c[1]) int c[1] c 1 for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
     i range(N) range N min_j = i min_j i for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
         j range(i, N) range i N if card[j]['value'] < card[min_j]['value']:
                min_j = j
         card[j]['value'] < card[min_j]['value'] card[j]['value'] [j] card j 'value' card[min_j]['value'] [min_j] card min_j 'value' min_j = j min_j j card[i], card[min_j] = card[min_j], card[i] card[i] card i card[min_j] card min_j card[min_j] card min_j card[i] card i new_C = [] new_C [] for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
     i range(N) range N new_C.append(card[i]['suit'] + str(card[i]['value'])) new_C.append new_C append card[i]['suit'] + str(card[i]['value']) card[i]['suit'] [i] card i 'suit' str(card[i]['value']) str card[i]['value'] [i] card i 'value' return new_C new_C C C N N N = int(input().rstrip()) N int(input().rstrip()) int input().rstrip() ().rstrip () input rstrip C = input().rstrip().split() C input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split C_b = bubble_sort(C, N) C_b bubble_sort(C, N) bubble_sort C N C_s = selection_sort(C, N) C_s selection_sort(C, N) selection_sort C N print(' '.join(C_b)) print ' '.join(C_b) ' '.join ' ' join C_b print('Stable') print 'Stable' print(' '.join(C_s)) print ' '.join(C_s) ' '.join ' ' join C_s if C_s == C_b:
    print('Stable')
else:
    print('Not stable') C_s == C_b C_s C_b print('Stable') print 'Stable' print('Not stable') print 'Not stable' def selection_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

    for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C def selection_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

    for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C selection_sort C_b = bubble_sort(C, N) bubble_sort(C, N) C_b C_s = selection_sort(C, N) selection_sort(C, N) C_s C = input().rstrip().split() input().rstrip().split() C N = int(input().rstrip()) int(input().rstrip()) N def bubble_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
    for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C def bubble_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
    for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C bubble_sort
def bubble_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})
            
    for i in range(N):
        for j in range(N-1, i, -1):
            if card[j]['value'] < card[j-1]['value']:
                card[j], card[j-1] = card[j-1], card[j]

    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C


def selection_sort(C, N):
    card = []
    for c in C:
        card.append({'suit': c[0], 'value': int(c[1])})

    for i in range(N):
        min_j = i
        for j in range(i, N):
            if card[j]['value'] < card[min_j]['value']:
                min_j = j
        card[i], card[min_j] = card[min_j], card[i]
        
    new_C = []
    for i in range(N):
        new_C.append(card[i]['suit'] + str(card[i]['value']))
        
    return new_C


N = int(input().rstrip())
C = input().rstrip().split()

C_b = bubble_sort(C, N)
C_s = selection_sort(C, N)

print(' '.join(C_b))
print('Stable')

print(' '.join(C_s))
if C_s == C_b:
    print('Stable')
else:
    print('Not stable')
