def partition(a, p, r)
  x = a[r][2]
  i = p - 1
  p.upto(r-1) do |j|
    if a[j][2] <= 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 quickSort(a, p, r)
  if p < r
    q = partition(a, p, r)
    quickSort(a, p, q-1)
    quickSort(a, q+1, r)
  end
end

def checkStable(origin, sorted)
  originOrder = {1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => ''}
  sortedOrder = {1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '', 7 => '', 8 => '', 9 => ''}
  (origin.size - 1).times do |i|
    originOrder[origin[i][2].to_i] << origin[i][0]
    sortedOrder[sorted[i][2].to_i] << sorted[i][0]
  end
  return originOrder == sortedOrder ? 'Stable' : 'Not stable'
end

a = []
n = gets.to_i
n.times do
  a.push(gets.to_s)
end
origin = Marshal.load(Marshal.dump(a))
quickSort(a, 0, a.size-1)
puts checkStable(origin, a)
puts a