hash = {}
que = []
n, q = gets.split(' ').map(&:to_i)
n.times do
  line = gets.chomp.split
  hash[line[0]] = line[1].to_i
  que.push(line[0])
end
done_hash = {}
time_stamp = 0
i = 0
while done_hash.length < n do
  res = hash[que[i]] - q
  if(res > 0)
    time_stamp += q
    hash[que[i]] = res
    que.push(que[i])
  else
    time_stamp += hash[que[i]]
    done_hash[que[i]] = time_stamp
  end
  que.delete_at(i)
end
done_hash.each do |key, val|
  puts "#{key} #{val}"
end
