#include <stdio.h>

#define TRUE 1
#define FALSE 0
#define LOOP_INIT 0
#define CARD_ARRAY_MAX 36
#define EXIT_SUCCESS 0
#define PREV_ITEM( x ) x - 1

int main( void )
{
	unsigned char ubW_Dcard_cnt;
	unsigned char ubW_Dbubble_card_mark_array[ CARD_ARRAY_MAX ];
	unsigned char ubW_Dbubble_card_num_array[ CARD_ARRAY_MAX ];
	unsigned char ubW_Dselect_card_mark_array[ CARD_ARRAY_MAX ];
	unsigned char ubW_Dselect_card_num_array[ CARD_ARRAY_MAX ];
	unsigned char ubW_Dtrade;
	unsigned char ubW_Dcard_min;
	unsigned char ubW_Floop_flug;
	unsigned char ubW_Cloop_cnt;
	unsigned char ubW_Cloop_sub_cnt;

	scanf( "%d", &ubW_Dcard_cnt );
	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < ubW_Dcard_cnt; ubW_Cloop_cnt++ ){
		scanf( "%c%d", &ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ], &ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] );
	}
	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < ubW_Dcard_cnt; ubW_Cloop_cnt++ ){
		ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ] = ubW_Dselect_card_mark_array[ ubW_Cloop_cnt ];
		ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] = ubW_Dselect_card_num_array[ ubW_Cloop_cnt ];
	}

	/* ?????????????????? */
	/* ?????????????????°???TRUE??????????????? */
	while( ubW_Floop_flug ){
		ubW_Floop_flug = FALSE;																			/* ?????????????????°???FALSE???			*/
		/* ???????????¨????????? */
		for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < ubW_Dcard_cnt; ubW_Cloop_cnt++ ){
			/* 1?????????????´?????????¨???????´?????????§????????´??? */
			if( ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] < ubW_Dbubble_card_num_array[ PREV_ITEM( ubW_Cloop_cnt ) ] ){
				ubW_Dtrade = ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ];										/* ????????¨?????°???????´??????????			*/
				ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] = ubW_Dbubble_card_num_array[ PREV_ITEM( ubW_Cloop_cnt ) ];	/* ?????¨???????´????1?????????????´?????????????	*/
				ubW_Dbubble_card_num_array[ PREV_ITEM( ubW_Cloop_cnt ) ] = ubW_Dtrade;							/* 1?????????????´?????????¨???????´?????????????	*/

				ubW_Dtrade = ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ];										/* ????????¨?????°???????´??????????			*/
				ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ] = ubW_Dbubble_card_mark_array[ PREV_ITEM( ubW_Cloop_cnt ) ];	/* ?????¨???????´????1?????????????´?????????????	*/
				ubW_Dbubble_card_mark_array[ PREV_ITEM( ubW_Cloop_cnt ) ] = ubW_Dtrade;							/* 1?????????????´?????????¨???????´?????????????	*/
				ubW_Floop_flug = TRUE;																	/* ?????????????????°???TRUE???				*/
			}
			else{
				/* else?????????????????????????????\ */
			}
		}/* ???????????¨?????????????????? */
	}/* ?????????????????°???TRUE???????????????????????? */
	/* ??????????????????????????? */

	/* ??????????????? */
	/* ?????????????±??????´????????? */
	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < ubW_Dcard_cnt; ubW_Cloop_cnt++ ){
		ubW_Dcard_min = ubW_Cloop_cnt;													/* ?????????????±?????¨????						*/
		/* ??????????±??????´????????? */
		for( ubW_Cloop_sub_cnt = ubW_Cloop_cnt; ubW_Cloop_sub_cnt < ubW_Dcard_cnt; ubW_Cloop_sub_cnt++){
			/* ??????????±?????????????????±????????°?????????´??? */
			if( ubW_Dselect_card_num_array[ ubW_Cloop_sub_cnt ] < ubW_Dselect_card_num_array[ ubW_Dcard_min ] ){
				ubW_Dcard_min = ubW_Cloop_sub_cnt;										/* ????°?????´????????´????????????´??°				*/
			}
			else{
				/* else?????????????????????????????\ */
			}
		}/* ??????????±??????´?????????????????? */
		/* ?????????????±????????´????????°?????´?????????§????????´??? */
		if( ubW_Dselect_card_num_array[ ubW_Cloop_cnt ] > ubW_Dselect_card_num_array[ ubW_Dcard_min ] ){
			ubW_Dtrade = ubW_Dselect_card_num_array[ ubW_Cloop_cnt ];								/* ????????¨?????°????????????????±????????´??????????	*/
			ubW_Dselect_card_num_array[ ubW_Cloop_cnt ] = ubW_Dselect_card_num_array[ ubW_Dcard_min ];			/* ?????????????±????????´????????°?????´?????????????	*/
			ubW_Dselect_card_num_array[ ubW_Dcard_min ] = ubW_Dtrade;									/* ????°?????´?????????????????±????????´?????????????	*/

			ubW_Dtrade = ubW_Dselect_card_mark_array[ ubW_Cloop_cnt ];								/* ????????¨?????°????????????????±????????´??????????	*/
			ubW_Dselect_card_mark_array[ ubW_Cloop_cnt ] = ubW_Dselect_card_mark_array[ ubW_Dcard_min ];			/* ?????????????±????????´????????°?????´?????????????	*/
			ubW_Dselect_card_mark_array[ ubW_Dcard_min ] = ubW_Dtrade;									/* ????°?????´?????????????????±????????´?????????????	*/
		}
		else{
			/* else?????????????????????????????\ */
		}
	}/* ?????????????±??????´?????????????????? */
	/* ???????????????????????? */

	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < PREV_ITEM( ubW_Dcard_cnt ); ubW_Cloop_cnt++){
		printf( "%c%d ", &ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ], &ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] );
	}
	printf( "%c%d\n", &ubW_Dbubble_card_mark_array[ PREV_ITEM( ubW_Dcard_cnt ) ], &ubW_Dbubble_card_num_array[ PREV_ITEM( ubW_Dcard_cnt ) ] );
	printf("Stable\n");
	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < PREV_ITEM( ubW_Dcard_cnt ); ubW_Cloop_cnt++){
		printf( "%c%d ", &ubW_Dselect_card_mark_array[ ubW_Cloop_cnt ], &ubW_Dselect_card_num_array[ ubW_Cloop_cnt ] );
	}
	printf( "%c%d\n", &ubW_Dselect_card_mark_array[ PREV_ITEM( ubW_Dcard_cnt ) ], &ubW_Dselect_card_num_array[ PREV_ITEM( ubW_Dcard_cnt ) ] );
	for( ubW_Cloop_cnt = LOOP_INIT; ubW_Cloop_cnt < ubW_Dcard_cnt; ubW_Cloop_cnt++){
		if( ubW_Dbubble_card_mark_array[ ubW_Cloop_cnt ] != ubW_Dselect_card_mark_array[ ubW_Cloop_cnt ] ){
			printf("Not stable\n");
			return EXIT_SUCCESS;
		}
		else{
			if( ubW_Dbubble_card_num_array[ ubW_Cloop_cnt ] != ubW_Dselect_card_num_array[ ubW_Cloop_cnt ] ){
				printf("Not stable\n");
				return EXIT_SUCCESS;
			}
			else{
				/* else?????????????????????????????\ */
			}
		}
	}
	printf("Stable\n");
	return EXIT_SUCCESS;
}