type t = {
  id : int;
  ch : char;
  num : int;
}

let rec partitoin a r = function
  | (i, j) when j = r ->
    let tmp = a.(i) in
    a.(i) <- a.(j);
    a.(j) <- tmp;
    i
  | (i, j) when a.(j).num <= a.(r).num ->
    let tmp = a.(i) in
    a.(i) <- a.(j);
    a.(j) <- tmp;
    partitoin a r (i + 1, j + 1)
  | (i, j) ->
    partitoin a r (i, j + 1)

let rec quick_sort a p r =
  if p < r then begin
    let q = partitoin a r (p, p) in
    quick_sort a p (q - 1);
    quick_sort a q r
  end

let rec stable_str a n i =
  if i = n then "Stable"
  else if a.(i-1).num = a.(i).num && a.(i-1).id > a.(i).id then "Not Stable"
  else stable_str a n (i + 1)

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

let () =
  let n = read_int () in
  let a = Array.init n (fun i ->
    match split (read_line ()) ' ' [] with
    | [c; d] -> { id = i; ch = c.[0]; num = int_of_string d }
    | _ -> exit 1) in
  quick_sort a 0 (n - 1);
  print_endline (stable_str a n 1);
  Array.iter (fun x -> Printf.printf "%c %d\n" x.ch x.num) a