n,q=gets.chomp.split(" ").map{|i|i.to_i}
ary=Array.new
bry=Array.new
time=0

for i in 0..n-1
	bry=gets.chomp.split(" ")
	bry=bry.push(bry.pop.to_i)
	ary=ary.push(bry)
end

loop{
	if ary==[]
		break
	elsif ary[0][1] > q
		ary[0][1] -= q
		ary=ary.push(ary.shift)
		time += q
		next
	elsif ary[0][1] <= q
		time+=ary[0][1]
		ary[0][1]=0
		print("#{ary.shift[0]} #{time}\n")
	end
}