import sys

queue = []

header = sys.stdin.readline()
(n, q) = header.strip().split()
q = int(q)

for line in sys.stdin.readlines():
  (name, time) = line.strip().split()
  queue.append((name, int(time)))

total_time = 0
while len(queue) > 0:
  (name, time) = queue.pop(0)
  time -= q
  if time > 0:
    total_time += q
    queue.append((name, time))
  else:
    total_time += time + q
    print "%s %s" % (name, total_time) import sys sys queue = [] queue [] header = sys.stdin.readline() header sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline (n, q) = header.strip().split() (n, q) n q header.strip().split() header.strip().split header.strip() header.strip header strip split q = int(q) q int(q) int q for line in sys.stdin.readlines():
  (name, time) = line.strip().split()
  queue.append((name, int(time))) line sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines (name, time) = line.strip().split() (name, time) name time line.strip().split() line.strip().split line.strip() line.strip line strip split queue.append((name, int(time))) queue.append queue append (name, int(time)) name int(time) int time total_time = 0 total_time 0 while len(queue) > 0:
  (name, time) = queue.pop(0)
  time -= q
  if time > 0:
    total_time += q
    queue.append((name, time))
  else:
    total_time += time + q
    print "%s %s" % (name, total_time) len(queue) > 0 len(queue) len queue 0 (name, time) = queue.pop(0) (name, time) name time queue.pop(0) queue.pop queue pop 0 time -= q time q if time > 0:
    total_time += q
    queue.append((name, time))
  else:
    total_time += time + q
    print "%s %s" % (name, total_time) time > 0 time 0 total_time += q total_time q queue.append((name, time)) queue.append queue append (name, time) name time total_time += time + q total_time time + q time q print "%s %s" % (name, total_time) "%s %s" (name, total_time) name total_time queue = [] [] queue q = int(q) int(q) q total_time = 0 0 total_time time -= q q time total_time += time + q time + q total_time header = sys.stdin.readline() sys.stdin.readline() header total_time += q q total_time
import sys

queue = []

header = sys.stdin.readline()
(n, q) = header.strip().split()
q = int(q)

for line in sys.stdin.readlines():
  (name, time) = line.strip().split()
  queue.append((name, int(time)))

total_time = 0
while len(queue) > 0:
  (name, time) = queue.pop(0)
  time -= q
  if time > 0:
    total_time += q
    queue.append((name, time))
  else:
    total_time += time + q
    print "%s %s" % (name, total_time)