
  def solve(n, cards)
    a = []
    b = []
    p cards
    for j in 0..(n-1)
      m = cards[j][0]
      i = cards[j][1].to_i
      a.push([m, i])
      b.push([m, i])
    end

    qsort(a, 0, n-1)

    stable = true
    (0..n-2).each do |i|
      if (a[i][1] == a[i+1][1])
        if b.index(a[i]) > b.index(a[i+1])
          stable = false
          break
        end
      end
    end

    if stable
      puts("Stable")
    else
      puts("Not stable")
    end

    a.each do |x|
      puts x.join(" ")
    end
  end

  def qsort(a, p, r)
    if p < r
      q = partion(a, p, r)
      qsort(a, p, q-1)
      qsort(a, q+1, r)
    end
  end

  def partion(a, p, r)
    x = a[r][1]
    i = p - 1
    (p...r).each do |j|
      if a[j][1] <= x
        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

n = gets.chomp.to_i
cards = []
n.times do
  card = gets.chomp.split
  cards.push(card)
end
solve(n, cards)