import scala.io.StdIn.{readInt,readLine}

object Main {
  def isStable(l:Array[(String, Int)],a:Array[(String, Int)]) = {
    val s = l.groupBy(_._2).filter(_._2.length > 1)
    var stable = true

    for { i <- s if stable }
      if(a.filter(_._2 == i._1).toSeq != i._2.toSeq)
        stable = false
    stable
  }

  def exchange(a:Array[(String,Int)],i:Int,j:Int) = {
    val temp = a(i)
    a(i) = a(j)
    a(j) = temp
  }

  def partition(a:Array[(String,Int)],p:Int,r:Int) = {
    val x = a(r)._2
    var i = (p-1)
    for(j<-p until r) {
      if(a(j)._2 <= x) {
        i+=1
        exchange(a,i,j)
      }
    }
    exchange(a,i+1,r)
    i+1
  }

  def quicksort(a:Array[(String,Int)],p:Int,r:Int):Unit = {
    if(p<r) {
      val q = partition(a,p,r)
      quicksort(a,p,q-1)
      quicksort(a,q+1,r)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = { for(i <- 1 to n) yield {
      val s = readLine.split(" ")
      (s(0),s(1).toInt)
    } }.toArray
    val org = a.clone
    quicksort(a,0,n-1)
    if(isStable(org,a))  println("Stable") else println("Not stable")
    println(a.map(e=>e._1+" "+e._2).mkString("\n"))
  }
}