n,q = gets.split.map(&:to_i)
queue = []
n.times{
  queue << gets.split
}
# n,q=5,100
# queue = [["p1",150],["p2",80],["p3",200],["p4",350],["p5",20]]
time = 0
def aqueue(n,q,queue,time)
  ans = []
  while queue.size != 0
    v = queue.shift
    if v[1].to_i <= q
      time += v[1].to_i
      ans.push("#{v[0]} #{time}")
    else
      time += q
      v[1] = v[1].to_i - q
      queue.push(v)
    end
  end
  return ans
end

puts aqueue(n,q,queue,time)