n,q = gets.to_i,gets.to_i
p = Array.new(n){gets.split(" ")}.map{|a| a[1].to_i}
total,done = 0,0
while(done<n)
  for i in 0..n-1
    if 0<p[i][1]&&p[i][1]<=q
      total+=p[i][1]
      puts("#{p[i][0]} #{total}")
      p[i][1]=0;
      done+=1
    elsif p[i][1]>0
      total+=q;
      p[i][1]-=q;
    end
  end
end