n, q = gets.split( " " ).map { |val| val.to_i }
ps = []
t = []
n.times { |i|
	ps[i], t[i] = gets.split( " " )
}

output = []
qsum = 0
while !t.empty?
	psi = ps.shift
	ti = t.shift.to_i
	if ti <= q
		qsum += ti	
		output.push( psi+" "+qsum.to_s )
	else
		t.push( ti - q )
		ps.push( psi )
		qsum += q
	end
end

puts( output.join( "\n" ) )