let quick_sort a cmp =
  let partition p r =
    let x = a.(r) in
    let swap i j =
      let t = a.(i) in a.(i) <- a.(j); a.(j) <- t
    in
    let rec doit i j =
      if j >= r then i
      else begin
        if cmp a.(j) x <= 0 then (swap (i + 1) j; doit (i + 1) (j + 1))
        else doit i (j + 1)
      end
    in
    let i = doit (p - 1) p in
    swap (i + 1) r;
    i + 1
  in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end
  in
  doit 0 (Array.length a - 1)

let stable_p a n =
  let cmp (xi, _, xd) (yi, _, yd) = xd = yd && xi < yi
  in
  let rec doit i =
    if i = n - 1 then true
    else if cmp a.(i) a.(i + 1) then doit (i + 1)
    else false
  in
  doit 0

let () =
  let n = read_int () in
  let a = Array.init n (fun i -> Scanf.scanf "%c %d\n" (fun c d -> (i, c, d))) in
  quick_sort a (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a