#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(){
  int flag=1,i,j,N,N2,swap,minj;

  //scanf N
  scanf("%d",&N);

  //making array
  N2 = N*2; //?????? + ??°??? ???????????????. +1???[????´???°]??\????????????????????????????????§??????????????¨???????????????
  char A_in[N2], A_out_b[N2], A_out_s[N2];

  //fill A_in[]
  for(i=0;i<N2;i++){ //?¢??????°???N2???????????????????????\??????????????°???N2-1(????????????????????????????????§???????????????)
    scanf(" %c",&A_in[i]); //getc???????????°"????????????????????????"????????¨
  }

  //copying A_in[] to each output Arrays
  for(i=0;i<N2;i++){
//    printf("%d: %c\n",i,A_in[i]);
    A_out_b[i] = A_in[i]; //bubble
    A_out_s[i] = A_in[i]; //selection
  }

  

  //BUBBLE SORT
  i=0;
  while(flag){
    flag = 0;
    for(j=N2-1;j>i+1;j-=2){ //???????????????????????°??????????????????????????????
      if(A_out_b[j]<A_out_b[j-2]){
        //int
        swap = A_out_b[j];
        A_out_b[j] = A_out_b[j-2];
        A_out_b[j-2] = swap;
        //char
        swap = A_out_b[j-1];
        A_out_b[j-1] = A_out_b[j-3];
        A_out_b[j-3] = swap;
        flag = 1; //to be continue
      }
    }
    i++;
  }

  //print Array
  for(i=0;i<N2;i++){
    printf("%c", A_out_b[i]);
    if(i!=0 && i%2!=0 && i<N2-1){ //1,3,5...?????¨??? i!=0(??????) i%2!=0(???????\???°) i<N2-1(???????????????)
      printf(" ");
    }
  }
  printf("\n");
  //print Stablily 
  printf("Stable\n"); //always 'Stable'
  
  
  //SELECTION SORT
  for(i=1;i<N2-2;i+=2){ //1??????(??????)????£???°??????2??????????????????????????????????????§
    minj = i; //first
    for(j=i;j<N2;j+=2){
      if(A_out_s[j]<A_out_s[minj]){ //update minj
        minj = j;
      }
    }
    //changing
    if(minj != i) {
      //int
      swap = A_out_s[i];
      A_out_s[i] = A_out_s[minj];
      A_out_s[minj] = swap;
      //char
      swap = A_out_s[i-1];
      A_out_s[i-1] = A_out_s[minj-1];
      A_out_s[minj-1] = swap;
    }
  }

  //print Array
  for(i=0;i<N2;i++){
    printf("%c", A_out_s[i]);
    if(i!=0 && i%2!=0 && i<N2-1){ //1,3,5...?????¨???
      printf(" ");
    }
  }
  printf("\n");
  
  //print Stablity
  if(strcmp(A_out_b, A_out_s) == 0){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  return 0;
}