n = int(input())
deck = input().split()

bd = list(deck)
for i in range(n):
    for j in reversed(range(i + 1, n)):
        if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j]
print(' '.join(bd))
print('Stable')

sd = list(deck)
for i in range(n):
    mi = i
    for j in range(i, n):
        if sd[j][1] < sd[mi][1]:
            mi = j
    sd[i], sd[mi] = sd[mi], sd[i]
print(' '.join(sd))

if (bd == sd):
    print('Stable')
else:
    print('Not stable') n = int(input()) n int(input()) int input() input deck = input().split() deck input().split() ().split () input split bd = list(deck) bd list(deck) list deck for i in range(n):
    for j in reversed(range(i + 1, n)):
        if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j] i range(n) range n for j in reversed(range(i + 1, n)):
        if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j] j reversed(range(i + 1, n)) reversed range(i + 1, n) range i + 1 i 1 n if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j] bd[j][1] < bd[j - 1][1] bd[j][1] [j] bd j 1 bd[j - 1][1] [j - 1] bd j - 1 j 1 1 bd[j], bd[j - 1] = bd[j - 1], bd[j] bd[j] bd j bd[j - 1] bd j - 1 j 1 bd[j - 1] bd j - 1 j 1 bd[j] bd j print(' '.join(bd)) print ' '.join(bd) ' '.join ' ' join bd print('Stable') print 'Stable' sd = list(deck) sd list(deck) list deck for i in range(n):
    mi = i
    for j in range(i, n):
        if sd[j][1] < sd[mi][1]:
            mi = j
    sd[i], sd[mi] = sd[mi], sd[i] i range(n) range n mi = i mi i for j in range(i, n):
        if sd[j][1] < sd[mi][1]:
            mi = j
     j range(i, n) range i n if sd[j][1] < sd[mi][1]:
            mi = j
     sd[j][1] < sd[mi][1] sd[j][1] [j] sd j 1 sd[mi][1] [mi] sd mi 1 mi = j mi j sd[i], sd[mi] = sd[mi], sd[i] sd[i] sd i sd[mi] sd mi sd[mi] sd mi sd[i] sd i print(' '.join(sd)) print ' '.join(sd) ' '.join ' ' join sd if (bd == sd):
    print('Stable')
else:
    print('Not stable') bd == sd bd sd print('Stable') print 'Stable' print('Not stable') print 'Not stable' bd = list(deck) list(deck) bd deck = input().split() input().split() deck n = int(input()) int(input()) n sd = list(deck) list(deck) sd mi = j j mi mi = i i mi
n = int(input())
deck = input().split()

bd = list(deck)
for i in range(n):
    for j in reversed(range(i + 1, n)):
        if bd[j][1] < bd[j - 1][1]:
            bd[j], bd[j - 1] = bd[j - 1], bd[j]
print(' '.join(bd))
print('Stable')

sd = list(deck)
for i in range(n):
    mi = i
    for j in range(i, n):
        if sd[j][1] < sd[mi][1]:
            mi = j
    sd[i], sd[mi] = sd[mi], sd[i]
print(' '.join(sd))

if (bd == sd):
    print('Stable')
else:
    print('Not stable')
