n,quantum = gets.split(" ").map(&:to_i)
process = []
n.times{
    p,t = gets.split
    t = t.to_i
    process << [p,t]
}

total = 0

while !process.empty?

	p,t = process.shift

	if t <= quantum
		total += t
		puts "#{p} #{total}"
	else
		t -= quantum
		total += quantum
		process << [p,t]
	end
end