# your code goes here
N=int(input())
Ci=[i for i in input().split()]
C=[]
for i in range(N):
   # print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1]))
Cb=C
fl=1
#print(Cb)
while fl==1:
    fl=0
    for j in range(N-1):
   #     print(Cb)
        if Cb[N-1-j][1]<Cb[N-2-j][1]:
       #     print(Cb)
            t=Cb[N-1-j]
            Cb[N-1-j]=Cb[N-2-j]
            Cb[N-2-j]=t
            fl=1
        #    print(C)
for i in range(N):
    Cb[i][1]=str(Cb[i][1])
 #   print(Cb)
    Cb[i]="".join(Cb[i])
print(" ".join(Cb))
p="Stable"
print(p)
C=[]
for i in range(N):
 #   print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1]))
Co=[]
for i in range(N):
    Co.append([])
  #  print(Co)
    Co[i].append(Ci[i][0])
    Co[i].append(int(Ci[i][1]))
for i in range(N-1):
    minj=i
    for j in range(i,N):
    #    print(C)
        if C[j][1]<C[minj][1]:
            minj=j
        elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
    if i!=minj:
        t=C[i]
        C[i]=C[minj]
        C[minj]=t
   # print(minj)
for i in range(N):
    C[i][1]=str(C[i][1])
    C[i]="".join(C[i])
print(" ".join(C))
print(p) N=int(input()) N int(input()) int input() input i for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() i Ci=[i for i in input().split()] Ci [i for i in input().split()] C=[] C [] for i in range(N):
   # print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1])) i range(N) range N C.append([]) C.append C append [] C[i].append(Ci[i][0]) [i].append [i] C i append Ci[i][0] [i] Ci i 0 C[i].append(int(Ci[i][1])) [i].append [i] C i append int(Ci[i][1]) int Ci[i][1] [i] Ci i 1 Cb=C Cb C fl=1 fl 1 while fl==1:
    fl=0
    for j in range(N-1):
   #     print(Cb)
        if Cb[N-1-j][1]<Cb[N-2-j][1]:
       #     print(Cb)
            t=Cb[N-1-j]
            Cb[N-1-j]=Cb[N-2-j]
            Cb[N-2-j]=t
            fl=1
        #    print(C) fl==1 fl 1 fl=0 fl 0 for j in range(N-1):
   #     print(Cb)
        if Cb[N-1-j][1]<Cb[N-2-j][1]:
       #     print(Cb)
            t=Cb[N-1-j]
            Cb[N-1-j]=Cb[N-2-j]
            Cb[N-2-j]=t
            fl=1
        #    print(C) j range(N-1) range N-1 N 1 if Cb[N-1-j][1]<Cb[N-2-j][1]:
       #     print(Cb)
            t=Cb[N-1-j]
            Cb[N-1-j]=Cb[N-2-j]
            Cb[N-2-j]=t
            fl=1
        #    print(C) Cb[N-1-j][1]<Cb[N-2-j][1] Cb[N-1-j][1] [N-1-j] Cb N-1-j N-1 N 1 j 1 Cb[N-2-j][1] [N-2-j] Cb N-2-j N-2 N 2 j 1 t=Cb[N-1-j] t Cb[N-1-j] Cb N-1-j N-1 N 1 j Cb[N-1-j]=Cb[N-2-j] Cb[N-1-j] Cb N-1-j N-1 N 1 j Cb[N-2-j] Cb N-2-j N-2 N 2 j Cb[N-2-j]=t Cb[N-2-j] Cb N-2-j N-2 N 2 j t fl=1 fl 1 for i in range(N):
    Cb[i][1]=str(Cb[i][1])
 #   print(Cb)
    Cb[i]="".join(Cb[i]) i range(N) range N Cb[i][1]=str(Cb[i][1]) Cb[i][1] [i] Cb i 1 str(Cb[i][1]) str Cb[i][1] [i] Cb i 1 Cb[i]="".join(Cb[i]) Cb[i] Cb i "".join(Cb[i]) "".join "" join Cb[i] Cb i print(" ".join(Cb)) print " ".join(Cb) " ".join " " join Cb p="Stable" p "Stable" print(p) print p C=[] C [] for i in range(N):
 #   print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1])) i range(N) range N C.append([]) C.append C append [] C[i].append(Ci[i][0]) [i].append [i] C i append Ci[i][0] [i] Ci i 0 C[i].append(int(Ci[i][1])) [i].append [i] C i append int(Ci[i][1]) int Ci[i][1] [i] Ci i 1 Co=[] Co [] for i in range(N):
    Co.append([])
  #  print(Co)
    Co[i].append(Ci[i][0])
    Co[i].append(int(Ci[i][1])) i range(N) range N Co.append([]) Co.append Co append [] Co[i].append(Ci[i][0]) [i].append [i] Co i append Ci[i][0] [i] Ci i 0 Co[i].append(int(Ci[i][1])) [i].append [i] Co i append int(Ci[i][1]) int Ci[i][1] [i] Ci i 1 for i in range(N-1):
    minj=i
    for j in range(i,N):
    #    print(C)
        if C[j][1]<C[minj][1]:
            minj=j
        elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
    if i!=minj:
        t=C[i]
        C[i]=C[minj]
        C[minj]=t
   # print(minj) i range(N-1) range N-1 N 1 minj=i minj i for j in range(i,N):
    #    print(C)
        if C[j][1]<C[minj][1]:
            minj=j
        elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
     j range(i,N) range i N if C[j][1]<C[minj][1]:
            minj=j
        elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
     C[j][1]<C[minj][1] C[j][1] [j] C j 1 C[minj][1] [minj] C minj 1 minj=j minj j elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
     C[j][1]==C[minj][1] C[j][1] [j] C j 1 C[minj][1] [minj] C minj 1 k=0 k 0 while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
             k<N and C[minj][1]!=Co[k][1] k<N k N C[minj][1]!=Co[k][1] C[minj][1] [minj] C minj 1 Co[k][1] [k] Co k 1 k+=1 k 1 if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
     k<N and C[minj][0]!=Co[k][0] k<N k N C[minj][0]!=Co[k][0] C[minj][0] [minj] C minj 0 Co[k][0] [k] Co k 0 p="Not stable" p "Not stable" if i!=minj:
        t=C[i]
        C[i]=C[minj]
        C[minj]=t
   # print(minj) i!=minj i minj t=C[i] t C[i] C i C[i]=C[minj] C[i] C i C[minj] C minj C[minj]=t C[minj] C minj t for i in range(N):
    C[i][1]=str(C[i][1])
    C[i]="".join(C[i]) i range(N) range N C[i][1]=str(C[i][1]) C[i][1] [i] C i 1 str(C[i][1]) str C[i][1] [i] C i 1 C[i]="".join(C[i]) C[i] C i "".join(C[i]) "".join "" join C[i] C i print(" ".join(C)) print " ".join(C) " ".join " " join C print(p) print p C=[] [] C fl=1 1 fl p="Stable" "Stable" p fl=1 1 fl k+=1 1 k p="Not stable" "Not stable" p Ci=[i for i in input().split()] [i for i in input().split()] Ci Co=[] [] Co fl=0 0 fl Cb=C C Cb k=0 0 k minj=i i minj minj=j j minj t=Cb[N-1-j] Cb[N-1-j] t t=C[i] C[i] t N=int(input()) int(input()) N C=[] [] C
# your code goes here
N=int(input())
Ci=[i for i in input().split()]
C=[]
for i in range(N):
   # print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1]))
Cb=C
fl=1
#print(Cb)
while fl==1:
    fl=0
    for j in range(N-1):
   #     print(Cb)
        if Cb[N-1-j][1]<Cb[N-2-j][1]:
       #     print(Cb)
            t=Cb[N-1-j]
            Cb[N-1-j]=Cb[N-2-j]
            Cb[N-2-j]=t
            fl=1
        #    print(C)
for i in range(N):
    Cb[i][1]=str(Cb[i][1])
 #   print(Cb)
    Cb[i]="".join(Cb[i])
print(" ".join(Cb))
p="Stable"
print(p)
C=[]
for i in range(N):
 #   print(C)
    C.append([])
    C[i].append(Ci[i][0])
  #  print(C)
    C[i].append(int(Ci[i][1]))
Co=[]
for i in range(N):
    Co.append([])
  #  print(Co)
    Co[i].append(Ci[i][0])
    Co[i].append(int(Ci[i][1]))
for i in range(N-1):
    minj=i
    for j in range(i,N):
    #    print(C)
        if C[j][1]<C[minj][1]:
            minj=j
        elif C[j][1]==C[minj][1]:
            k=0
            while k<N and C[minj][1]!=Co[k][1]:
                k+=1
    #        print (j)
            if k<N and C[minj][0]!=Co[k][0]:
                p="Not stable"
    if i!=minj:
        t=C[i]
        C[i]=C[minj]
        C[minj]=t
   # print(minj)
for i in range(N):
    C[i][1]=str(C[i][1])
    C[i]="".join(C[i])
print(" ".join(C))
print(p)