let swap a i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp

let rec partition (a : (int * char * int) array) r cmp = function
  | (i, j) when j = r -> swap a i r; i
  | (i, j) when cmp a.(j) a.(r) <= 0 -> swap a i j; partition a r cmp (i + 1, j + 1)
  | (i, j) -> partition a r cmp (i, j + 1)

let rec quick_sort (a : (int * char * int) array) p r cmp =
  if p < r then begin
    let q = partition a r cmp (p, p) in
    quick_sort a p (q - 1) cmp;
    quick_sort a q r cmp
  end

let rec stable_p (a : (int * char * int) array) n i =
  if i = n then true
  else if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then false
  else stable_p a n (i + 1)

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let () =
  let n = read_int () in
  let read i =
    match split (read_line ()) ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> exit 1 in
  let a = Array.init n read in
  quick_sort a 0 (n - 1) (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n 1 then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a