package main

/*
クイックソート
*/

import (
	"bufio"
	"bytes"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

// Card カード
type Card struct {
	suit string
	num  int
}

func (c *Card) String() string {
	return fmt.Sprintf("%s %d", c.suit, c.num)
}

type cards []*Card

func (cs cards) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range cs {
		buf.WriteString(fmt.Sprintf("%s%s", sep, v))
		sep = " "
	}
	return buf.String()
}

func merge(left, right []*Card) {
	a := append(left, right...)
	tmpl := make([]*Card, len(left)+1)
	tmpr := make([]*Card, len(right)+1)
	copy(tmpl, left)
	copy(tmpr, right)
	tmpl[len(tmpl)-1] = &Card{"?", 1000000001}
	tmpr[len(tmpr)-1] = &Card{"?", 1000000001}
	i, j := 0, 0
	for k := 0; k < len(a); k++ {
		if tmpl[i].num <= tmpr[j].num {
			a[k] = tmpl[i]
			i++
		} else {
			a[k] = tmpr[j]
			j++
		}
	}
}

func mergeSort(a []*Card) {
	if len(a) > 1 {
		mid := len(a) / 2
		left := a[:mid]
		right := a[mid:]
		mergeSort(left)
		mergeSort(right)
		merge(left, right)
	}
}

/*
なぜピボットを最後尾にするかといえば，
それはpartitionのアルゴリズムが，
最後尾がピボットだとやりやすいからである．
uickSortを最後尾以外の要素をピボットにするには，
quickSort開始時に，任意のピボットを最後尾の要素と入れ替えておけばいい.
*/
func partition(a []*Card) int {
	x := a[len(a)-1]
	i := -1
	for j := 0; j < len(a)-1; j++ {
		if a[j].num <= x.num {
			i++
			a[i], a[j] = a[j], a[i]
		}
	}
	a[i+1], a[len(a)-1] = a[len(a)-1], a[i+1]
	return i + 1
}
func quickSort(a []*Card) {
	if len(a) > 1 {
		q := partition(a)
		quickSort(a[:q])
		quickSort(a[q+1:])
	}
}
func sliceEq(a, b []*Card) bool {
	if len(a) != len(b) {
		return false
	}
	for i := 0; i < len(a); i++ {
		if !(a[i].num == b[i].num && a[i].suit == b[i].suit) {
			return false
		}
	}
	return true
}

func main() {
	scanner := makeScanner(256)
	n := eGetInt(scanner)
	forQsort := make([]*Card, 0, n)
	forMsort := make([]*Card, 0, n)
	for i := 0; i < n; i++ {
		info := eGetFields(scanner)
		forQsort = append(forQsort, &Card{info[0], eAtoi(info[1])})
		forMsort = append(forMsort, &Card{info[0], eAtoi(info[1])})
	}
	mergeSort(forMsort)
	quickSort(forQsort)
	if sliceEq(forQsort, forMsort) {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
	var buf bytes.Buffer
	for _, c := range forQsort {
		buf.WriteString(fmt.Sprintln(c))
	}
	fmt.Print(buf.String())
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}

type ints []int

func (s ints) String() string {
	var buf bytes.Buffer
	sep := ""
	for _, v := range s {
		buf.WriteString(fmt.Sprintf("%s%d", sep, v))
		sep = " "
	}
	return buf.String()
}

func reverse(a ints) ints {
	r := make(ints, len(a))
	for i := 0; i < len(a); i++ {
		r[i] = a[len(a)-1-i]
	}
	return r
}
func max(a ints) (int, bool) {
	if len(a) == 0 {
		return 0, false
	}
	m := a[0]
	for _, e := range a {
		if e > m {
			m = e
		}
	}
	return m, true
}
func sum(a ints) int {
	if len(a) == 0 {
		return 0
	}
	sum := 0
	for _, e := range a {
		sum += e
	}
	return sum
}



Measured memory_bytes: 20352