from collections import deque

nameq = deque()
timeq = deque()
n, q = map(int, raw_input().split())
for _ in xrange(n):
  name, time = raw_input().split()
  nameq.append(name)
  timeq.append(int(time))

t = 0
while nameq:
  name = nameq.popleft()
  time = timeq.popleft()
  if time > q:
    time -= q
    nameq.append(name)
    timeq.append(time)
    t += q
  else:
    t += time
    print "%s %d" % (name, t) from collections import deque nameq = deque() nameq deque() deque timeq = deque() timeq deque() deque n, q = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q for _ in xrange(n):
  name, time = raw_input().split()
  nameq.append(name)
  timeq.append(int(time)) _ xrange(n) xrange n name, time = raw_input().split() name raw_input().split() ().split () raw_input split time nameq.append(name) nameq.append nameq append name timeq.append(int(time)) timeq.append timeq append int(time) int time t = 0 t 0 while nameq:
  name = nameq.popleft()
  time = timeq.popleft()
  if time > q:
    time -= q
    nameq.append(name)
    timeq.append(time)
    t += q
  else:
    t += time
    print "%s %d" % (name, t) nameq name = nameq.popleft() name nameq.popleft() nameq.popleft nameq popleft time = timeq.popleft() time timeq.popleft() timeq.popleft timeq popleft if time > q:
    time -= q
    nameq.append(name)
    timeq.append(time)
    t += q
  else:
    t += time
    print "%s %d" % (name, t) time > q time q time -= q time q nameq.append(name) nameq.append nameq append name timeq.append(time) timeq.append timeq append time t += q t q t += time t time print "%s %d" % (name, t) "%s %d" (name, t) name t timeq = deque() deque() timeq q = map(int, raw_input().split()) map(int, raw_input().split()) q t += time time t nameq = deque() deque() nameq t = 0 0 t time -= q q time t += q q t name = nameq.popleft() nameq.popleft() name n, q = map(int, raw_input().split()) map(int, raw_input().split()) n name, time = raw_input().split() raw_input().split() name time = timeq.popleft() timeq.popleft() time time = raw_input().split() raw_input().split() time
from collections import deque

nameq = deque()
timeq = deque()
n, q = map(int, raw_input().split())
for _ in xrange(n):
  name, time = raw_input().split()
  nameq.append(name)
  timeq.append(int(time))

t = 0
while nameq:
  name = nameq.popleft()
  time = timeq.popleft()
  if time > q:
    time -= q
    nameq.append(name)
    timeq.append(time)
    t += q
  else:
    t += time
    print "%s %d" % (name, t)