n,q = gets.split.map(&:to_i)
a = []
n.times{
  a << gets.split
}
time = 0
def queue(a,time,q)
  r = a.shift
  ans = ""
  if r[1].to_i <= q
    time += r[1].to_i
    puts "#{r[0]} #{time}"
    return if a.size == 0
  else
    r[1] = r[1].to_i - q
    time += q
    a.push(r)
  end
  queue(a,time,q)
end
queue(a,time,q)