# your code goes here
require 'thread'
n,q=STDIN.gets.split(" ")
n=n.to_i
q=q.to_i
qu=Queue.new
n.times do |i|
n1,t1=STDIN.gets.split(" ")
qu<<[n1,t1.to_i]
end
th1=Thread.start do
time=0
while !qu.empty?
a=qu.pop
if a[1]<=q
time+=a[1]
print a[0]<<" "
puts time
else
time+=q
t2=a[1]-q
qu.push([a[0],t2])
end
end
end
th1.join