def part(a, q, r)
  x = a[r][1]
  i = q - 1
  for j in 0...r - q
    if a[q + j][1] <= x
      i += 1
      a[i], a[q + j] = a[q + j], a[i]
    end
  end
  a[i + 1], a[r] = a[r], a[i + 1]
  return i + 1
end
def qsort(a, q = nil, r = nil)
  q, r = 0, a.length - 1 if !q
  if q < r
    x = part(a, q, r)
    qsort(a, q, x - 1)
    qsort(a, x + 1, r)
  end
end
cards = []
gets.to_i.times do
  cards << gets.split(" ")
  cards.last[1] = cards.last[1].to_i
end
cards2 = cards.dup
qsort(cards)
i = 0
cards2.sort_by{|item|
  i += 1
  [item[1], i]
  }
bool = true
cards.each_with_index{|item,idx|
  bool &&= item == cards2[idx]
  }
if bool
  puts "Stable"
else
  puts "Not stable"
end
cards.each{|item|puts item.join(" ")}