n,q = gets.split.map {|s| s.to_i}
Dat = Struct.new(:name,:time)
que = Array.new()
for i in 0...n
  name,time = gets.split
  que.push(Dat.new(name,time.to_i))
end
t = 0
until que.empty?
  d = que.shift
  if d.time <= q
    t += d.time
    puts d.name + " " + t.to_s
  else
    t += q
    d.time -= q
    que.push(d)
  end
end