n = gets.to_i
a = Array.new(n){
  gets.split.map{|i|
    if !i.match(/(S|H|C|D)/)
      i.to_i
    else
      i
    end
  }
}

$INF = 10**9

def partition(a, p, r)
  x = a[r][1]

  i=p-1
  p.upto(r-1) do |j|
    if a[j][1] <= x
      i = i+1
      a[i], a[j] = a[j], a[i]
    end
  end
  a[i+1], a[r] = a[r], a[i+1]
  return i+1
end

def quick_sort(a, p, r)
  if p < r
    q = partition(a, p, r)
    quick_sort(a, p, q-1)
    quick_sort(a, q+1, r)
  end
end

def marge(l, r)
  l.push([nil, $INF])
  r.push([nil, $INF])
  length = l.length-1 + r.length-1
  return Array.new(length){(l.first[1] <= r.first[1] ? l : r).shift}
end

def marge_sort(s)
  if s.length >= 2
    mid = s.length/2
    l = marge_sort(s[0..mid-1])
    r = marge_sort(s[mid..-1])
    s = marge(l, r)
  end
  return s
end

b = marge_sort(a)
quick_sort(a, 0, n-1)

puts a == b ? "Stable" : "Not stable"
puts a.map{|item| item.join(" ")}
