use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min, max};

struct Scanner<R: Read> {
    reader: R,
    buffer: String,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader, buffer: String::new() }
    }

    // fn line(&mut self) -> String {
    //     self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
    //         .skip_while(|&c| c == '\n' || c == '\r')
    //         .take_while(|&c| !(c == '\n' || c == '\r'))
    //         .collect::<String>();
    //     self.buffer.clone()
    // }

    fn read_buffer(&mut self) {
        self.buffer = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        self.read_buffer();
        if self.buffer.is_empty() {
            None
        } else {
            self.buffer.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            // writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item=U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

type Card = (char, u32, usize);

fn partition(a: &mut[Card]) -> usize {
    let n = a.len();
    let mut i = 0;
    let x = *a.last().unwrap();
    for j in 0..n{
        if a[j].1 <= x.1 {
            a.swap(i, j);
            i += 1;
        }
    }
    i - 1
}

fn quick_sort(a: &mut[Card]) {
    if a.len() >= 2 {
        let p = partition(a);
        quick_sort(&mut a[..p]);
        quick_sort(&mut a[p..]);
    }
}

fn check_stable(a: &[Card]) -> bool {
    let mut map = HashMap::new();
    a.iter().all(|&(_, r, i)| {
        let prev = map.entry(r).or_insert(0);
        if *prev > i {
            false
        } else {
            *prev = i;
            true
        }
    })
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n: usize = sc.read();
        let mut a: Vec<Card> = (0..n).map(|i| {
            let s: String = sc.read();
            let r: u32 = sc.read();
            (s.chars().next().unwrap(), r, i)
        }).collect();

        quick_sort(&mut a[..]);
        println!("{}", if check_stable(&a) { "Stable" } else { "Not stable" });
        for &(s, r, _) in a.iter() {
            println!("{} {}", s, r);
        }
    }
}



Measured memory_bytes: 11220