class Proq
	attr_reader:name
	def initialize(line)
		d = line.split(" ")
		@name = d[0]
		@time = d[1].to_i
	end
	def cul(t)
		@time -= t
	end
end

queue = Array.new

d = gets.chomp.split(" ").map(&:to_i)
n,q = d[0],d[1]
n.times { queue << Proq.new(gets) }

time = 0
while queue.length > 0
	time += q
	p = queue.slice!(0)
	remain = p.cul(q)
	if remain > 0
		queue << p
	else
		time += remain
		puts "#{p.name} #{time}"
	end
end