n = int(input())
a = list(input().split())
b = a[:]
for i in range(n):
    for j in range(n-1):
        if a[j][1]>a[j+1][1]:
            a[j],a[j+1] = a[j+1],a[j]
    minj = i
    for j in range(i,n):
        if b[minj][1]>b[j][1]:
            minj = j
    b[minj],b[i] = b[i],b[minj]        
print(*a)
print('Stable')
print(*b)
print(['Not s','S'][a==b] + 'table')


 n = int(input()) n int(input()) int input() input a = list(input().split()) a list(input().split()) list input().split() ().split () input split b = a[:] b a[:] a : for i in range(n):
    for j in range(n-1):
        if a[j][1]>a[j+1][1]:
            a[j],a[j+1] = a[j+1],a[j]
    minj = i
    for j in range(i,n):
        if b[minj][1]>b[j][1]:
            minj = j
    b[minj],b[i] = b[i],b[minj]         i range(n) range n for j in range(n-1):
        if a[j][1]>a[j+1][1]:
            a[j],a[j+1] = a[j+1],a[j]
     j range(n-1) range n-1 n 1 if a[j][1]>a[j+1][1]:
            a[j],a[j+1] = a[j+1],a[j]
     a[j][1]>a[j+1][1] a[j][1] [j] a j 1 a[j+1][1] [j+1] a j+1 j 1 1 a[j],a[j+1] = a[j+1],a[j] a[j] a j a[j+1] a j+1 j 1 a[j+1] a j+1 j 1 a[j] a j minj = i minj i for j in range(i,n):
        if b[minj][1]>b[j][1]:
            minj = j
     j range(i,n) range i n if b[minj][1]>b[j][1]:
            minj = j
     b[minj][1]>b[j][1] b[minj][1] [minj] b minj 1 b[j][1] [j] b j 1 minj = j minj j b[minj],b[i] = b[i],b[minj] b[minj] b minj b[i] b i b[i] b i b[minj] b minj print(*a) print *a a print('Stable') print 'Stable' print(*b) print *b b print(['Not s','S'][a==b] + 'table') print ['Not s','S'][a==b] + 'table' ['Not s','S'][a==b] ['Not s','S'] 'Not s' 'S' a==b a b 'table' minj = j j minj minj = i i minj n = int(input()) int(input()) n a = list(input().split()) list(input().split()) a b = a[:] a[:] b
n = int(input())
a = list(input().split())
b = a[:]
for i in range(n):
    for j in range(n-1):
        if a[j][1]>a[j+1][1]:
            a[j],a[j+1] = a[j+1],a[j]
    minj = i
    for j in range(i,n):
        if b[minj][1]>b[j][1]:
            minj = j
    b[minj],b[i] = b[i],b[minj]        
print(*a)
print('Stable')
print(*b)
print(['Not s','S'][a==b] + 'table')



