class Card
  attr_accessor :suit, :num
  def initialize(s)
    @suit = s[0]
    @num = s[1].to_i
  end
  def val
    return @suit + " " + @num.to_s
  end
end

def partition(a,p,r)
  x = a[r]
  i = p
  (p..r-1).each do |j|
    if a[j].num <= x.num
      a[i],a[j] = a[j],a[i]
      i = i+1
    end
  end
  a[i],a[r] = a[r],a[i]
  return i
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 isStable(a,b,n)
  for ai in 0..n-2 do
    for bi in 1..n-1 do
      if a[ai]!=b[bi]
        next
      end
      for aj in ai+1..n-1 do
        if a[ai].num!=a[aj].num
          next
        end
        for bj in 0..bi-1 do
          if a[aj]==b[bj]
            return "Not stable"
          end
        end
      end
    end
  end
  return "Stable"
end 

n = gets.to_i
a = []
(0...n).each do |i|
  a[i] = Card.new(gets.split)
end

b = a.clone
quickSort(b,0,n-1)
printf("%s\n%s\n",isStable(a,b,n),b.map(&:val).join("\n"))
