n=int(input())
b=input().split()
s=b[:]
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]
    m=i
    for j in range(i,n):
        if s[m][1]>s[j][1]:m=j
    s[m],s[i]=s[i],s[m]
print(*b)
print('Stable')
print(*s)
print(['Not s','S'][b==s]+'table') n=int(input()) n int(input()) int input() input b=input().split() b input().split() ().split () input split s=b[:] s b[:] b : 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]
    m=i
    for j in range(i,n):
        if s[m][1]>s[j][1]:m=j
    s[m],s[i]=s[i],s[m] 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 m=i m i for j in range(i,n):
        if s[m][1]>s[j][1]:m=j
     j range(i,n) range i n if s[m][1]>s[j][1]:m=j
     s[m][1]>s[j][1] s[m][1] [m] s m 1 s[j][1] [j] s j 1 s[m],s[i]=s[i],s[m] s[m] s m s[i] s i s[i] s i s[m] s m print(*b) print *b b print('Stable') print 'Stable' print(*s) print *s s print(['Not s','S'][b==s]+'table') print ['Not s','S'][b==s]+'table' ['Not s','S'][b==s] ['Not s','S'] 'Not s' 'S' b==s b s 'table' m=i i m b=input().split() input().split() b n=int(input()) int(input()) n s=b[:] b[:] s
n=int(input())
b=input().split()
s=b[:]
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]
    m=i
    for j in range(i,n):
        if s[m][1]>s[j][1]:m=j
    s[m],s[i]=s[i],s[m]
print(*b)
print('Stable')
print(*s)
print(['Not s','S'][b==s]+'table')