n = int(input())
a = input().strip().split()
#Bubble sort
b = a[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j]
print(' '.join(b))
print('Stable')
#Selection sort
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
    a[i],a[minj] = a[minj],a[i]
print(' '.join(a))
print('Stable' if b == a else 'Not stable') n = int(input()) n int(input()) int input() input a = input().strip().split() a input().strip().split() ().strip().split ().strip() ().strip () input strip split b = a[:] b a[:] a : for i in range(n):
    for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j] i range(n) range n for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j] j range(n-1,i,-1) range n-1 n 1 i -1 if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j] b[j][1] < b[j-1][1] b[j][1] [j] b j 1 b[j-1][1] [j-1] b j-1 j 1 1 b[j],b[j-1] = b[j-1],b[j] b[j] b j b[j-1] b j-1 j 1 b[j-1] b j-1 j 1 b[j] b j print(' '.join(b)) print ' '.join(b) ' '.join ' ' join b print('Stable') print 'Stable' for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
    a[i],a[minj] = a[minj],a[i] i range(n) range n minj = i minj i for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
     j range(i,n) range i n if a[j][1] < a[minj][1]:
            minj = j
     a[j][1] < a[minj][1] a[j][1] [j] a j 1 a[minj][1] [minj] a minj 1 minj = j minj j a[i],a[minj] = a[minj],a[i] a[i] a i a[minj] a minj a[minj] a minj a[i] a i print(' '.join(a)) print ' '.join(a) ' '.join ' ' join a print('Stable' if b == a else 'Not stable') print 'Stable' if b == a else 'Not stable' b == a b a 'Stable' 'Not stable' n = int(input()) int(input()) n a = input().strip().split() input().strip().split() a b = a[:] a[:] b minj = i i minj minj = j j minj
n = int(input())
a = input().strip().split()
#Bubble sort
b = a[:]
for i in range(n):
    for j in range(n-1,i,-1):
        if b[j][1] < b[j-1][1]:
            b[j],b[j-1] = b[j-1],b[j]
print(' '.join(b))
print('Stable')
#Selection sort
for i in range(n):
    minj = i
    for j in range(i,n):
        if a[j][1] < a[minj][1]:
            minj = j
    a[i],a[minj] = a[minj],a[i]
print(' '.join(a))
print('Stable' if b == a else 'Not stable')