def rrs()
  a = gets.split(' ').map(&:to_i)
  n = a[0]
  t = a[1]
  ct = 0
  q = []
  for i in 0..n-1
    q[i] = gets.split(' ')
  end
  while q.size > 0
    n = q.shift
    m = n[1].to_i
    if m <= t
      ct += m
      print n[0], ' '
      puts ct
    else
      m -= t
      ct += t
      n[1] = m
      q.push(n)
    end
  end
end

rrs()