#include<stdio.h>
#define N 36

struct kazu {
  int value;
  char mozi;
}

main(){
  int i,j,n;
  char m;
  struct kazu a[N],d[N],b,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%c%d",&a[i].mozi,&a[i].value);
    d[i] = a[i];
  }

  for(i=0;i<n-1;i++){
    minj = i;
    for(j=n-1;j<i;j--){
      if(a[j].value < a[j-1].value){
	minj = j;
      }
      b = a[j];
      a[j] = a[j-1];
      a[minj] = b;
    }
  }
  
  printf("%c%d",a[0].mozi,a[0].value);
  for(i=1;i<n-1;i++){
    printf(" %c%d",a[i].mozi,a[i].value);
  }
  printf("Stable\n");
  
  
  
  
  
  
  
  for(i=0;i<n-1;i++){
    minj = i;
    for(j=i;j<n-1;j++){
      if(d[j].value < d[minj].value){
	minj = j;
      }
      e = d[j];
      d[j] = d[j-1];
      d[minj] = e;
    }
  }
  
  if()
    
    
    return 0;
}

   