n = gets.to_i

a = []
b = []

n.times{
    m, i = gets.split
    a.push([m, i.to_i])
    b.push([m, i.to_i])
}

def pertition(a, p, r)
    x = a[r][1]
    i = p - 1
    for j in p .. r - 1
        if a[j][1] <= x then 
            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 then
        q = pertition(a, p, r)
        quickSort(a, p, q-1)
        quickSort(a, q+1, r)
    end
    return a
end

a = quickSort(a, 0, a.length - 1)

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

if stable then
    puts "Stable"
else
    puts "Not stable"
end

a.each{|k|
    puts k.join(" ")
}
