def bblsrt(cards):
    cards1 = cards.copy()
    for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
    return cards1


def slcsrt(cards):
    cards2 = cards.copy()
    for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
    return cards2


n = int(input())
C = list(input().split())
print(' '.join(bblsrt(C)))
print('Stable')
print(' '.join(slcsrt(C)))
print('Stable' if slcsrt(C) == bblsrt(C) else 'Not stable')
 def bblsrt(cards):
    cards1 = cards.copy()
    for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
    return cards1 bblsrt cards1 = cards.copy() cards1 cards.copy() cards.copy cards copy for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
     i range(len(cards1)) range len(cards1) len cards1 for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
     j range(len(cards1) - 1, i, -1) range len(cards1) - 1 len(cards1) len cards1 1 i -1 if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
     cards1[j][1] < cards1[j - 1][1] cards1[j][1] [j] cards1 j 1 cards1[j - 1][1] [j - 1] cards1 j - 1 j 1 1 cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j] cards1[j] cards1 j cards1[j - 1] cards1 j - 1 j 1 cards1[j - 1] cards1 j - 1 j 1 cards1[j] cards1 j return cards1 cards1 cards cards def slcsrt(cards):
    cards2 = cards.copy()
    for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
    return cards2 slcsrt cards2 = cards.copy() cards2 cards.copy() cards.copy cards copy for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
     i range(len(cards2)) range len(cards2) len cards2 minj = i minj i for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
         j range(i, len(cards2)) range i len(cards2) len cards2 if cards2[j][1] < cards2[minj][1]:
                minj = j
         cards2[j][1] < cards2[minj][1] cards2[j][1] [j] cards2 j 1 cards2[minj][1] [minj] cards2 minj 1 minj = j minj j cards2[i], cards2[minj] = cards2[minj], cards2[i] cards2[i] cards2 i cards2[minj] cards2 minj cards2[minj] cards2 minj cards2[i] cards2 i return cards2 cards2 cards cards n = int(input()) n int(input()) int input() input C = list(input().split()) C list(input().split()) list input().split() ().split () input split print(' '.join(bblsrt(C))) print ' '.join(bblsrt(C)) ' '.join ' ' join bblsrt(C) bblsrt C print('Stable') print 'Stable' print(' '.join(slcsrt(C))) print ' '.join(slcsrt(C)) ' '.join ' ' join slcsrt(C) slcsrt C print('Stable' if slcsrt(C) == bblsrt(C) else 'Not stable') print 'Stable' if slcsrt(C) == bblsrt(C) else 'Not stable' slcsrt(C) == bblsrt(C) slcsrt(C) slcsrt C bblsrt(C) bblsrt C 'Stable' 'Not stable' def bblsrt(cards):
    cards1 = cards.copy()
    for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
    return cards1 def bblsrt(cards):
    cards1 = cards.copy()
    for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
    return cards1 bblsrt C = list(input().split()) list(input().split()) C def slcsrt(cards):
    cards2 = cards.copy()
    for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
    return cards2 def slcsrt(cards):
    cards2 = cards.copy()
    for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
    return cards2 slcsrt n = int(input()) int(input()) n
def bblsrt(cards):
    cards1 = cards.copy()
    for i in range(len(cards1)):
        for j in range(len(cards1) - 1, i, -1):
            if cards1[j][1] < cards1[j - 1][1]:
                cards1[j], cards1[j - 1] = cards1[j - 1], cards1[j]
    return cards1


def slcsrt(cards):
    cards2 = cards.copy()
    for i in range(len(cards2)):
        minj = i
        for j in range(i, len(cards2)):
            if cards2[j][1] < cards2[minj][1]:
                minj = j
        cards2[i], cards2[minj] = cards2[minj], cards2[i]
    return cards2


n = int(input())
C = list(input().split())
print(' '.join(bblsrt(C)))
print('Stable')
print(' '.join(slcsrt(C)))
print('Stable' if slcsrt(C) == bblsrt(C) else 'Not stable')

