n, q = gets.split.map(&:to_i)
time = 0
queue = {}
results = []

n.times do
  k, v = gets.split
  queue[k] = v.to_i
end

until queue.empty?
  k, v = queue.shift
  if v > q
    time += q
    v -= q
    queue[k] = v
  else
    time += v
    results << [k, time]
  end
end

results.each { |v| puts v * ' ' }

