n = gets.chomp.split(" ").map(&:to_i)
a = []
que = []
n[0].times do |i|
  a[i] = gets.chomp.split(" ")
  a[i][1] = a[i][1].to_i
  que.push(a[i])
end
time = 0
while(que.size > 0)
  t = que.shift
  if(t[1] <= n[1])
    time += t[1]
    puts("#{t[0]} #{time}")
  else
    time += n[1]
    que.push([t[0],t[1] - n[1]])
  end
end