def get_input_as_hash(num)
  hash={}
  for i in 1..num
    line = readline.split(/[[:space:]]/)
    hash.store(line[0],line[1].to_i)
  end
  hash
end

def queue_calc(hash,limit_time,totaltime=0)
  tmp_array=[]
  hash.each do |key,val|
    if val>limit_time
      hash[key] = val-limit_time
      tmp_array.push hash.assoc(key)
      hash.delete(key)
      totaltime += limit_time
    else
      hash[key]=val+totaltime
      totaltime = hash[key]
    end
  end
  if tmp_array.size!=0
    new_hash = {}
    #print tmp_array
    tmp_array.each do |hashset|
      new_hash.store(hashset[0],hashset[1])
    end
    new_hash = queue_calc(new_hash,limit_time,totaltime)
    hash.merge! new_hash
  end
  hash
end

def queue
  input = readline.split(/[[:space:]]/)
  line_count = input[0].to_i
  limit_time = input[1].to_i
  q=queue_calc(get_input_as_hash(line_count),limit_time)
  q.each do |key,val|
    print "#{key} #{val}\n"
  end
end

queue