queue = []

n, q = map(int, input().split())
for i in range(n):
  name, time = input().split()
  queue.append([name, int(time)])

t = 0
while len(queue) > 0:
  entry = queue.pop(0)
  t += min(entry[1], q)
  entry[1] -= q
  if entry[1] > 0:
    queue.append(entry)
  else:
    print("{} {}".format(entry[0], t)) queue = [] queue [] n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q for i in range(n):
  name, time = input().split()
  queue.append([name, int(time)]) i range(n) range n name, time = input().split() name input().split() ().split () input split time queue.append([name, int(time)]) queue.append queue append [name, int(time)] name int(time) int time t = 0 t 0 while len(queue) > 0:
  entry = queue.pop(0)
  t += min(entry[1], q)
  entry[1] -= q
  if entry[1] > 0:
    queue.append(entry)
  else:
    print("{} {}".format(entry[0], t)) len(queue) > 0 len(queue) len queue 0 entry = queue.pop(0) entry queue.pop(0) queue.pop queue pop 0 t += min(entry[1], q) t min(entry[1], q) min entry[1] entry 1 q entry[1] -= q entry[1] entry 1 q if entry[1] > 0:
    queue.append(entry)
  else:
    print("{} {}".format(entry[0], t)) entry[1] > 0 entry[1] entry 1 0 queue.append(entry) queue.append queue append entry print("{} {}".format(entry[0], t)) print "{} {}".format(entry[0], t) "{} {}".format "{} {}" format entry[0] entry 0 t n, q = map(int, input().split()) map(int, input().split()) n t += min(entry[1], q) min(entry[1], q) t t = 0 0 t entry = queue.pop(0) queue.pop(0) entry name, time = input().split() input().split() name queue = [] [] queue time = input().split() input().split() time q = map(int, input().split()) map(int, input().split()) q
queue = []

n, q = map(int, input().split())
for i in range(n):
  name, time = input().split()
  queue.append([name, int(time)])

t = 0
while len(queue) > 0:
  entry = queue.pop(0)
  t += min(entry[1], q)
  entry[1] -= q
  if entry[1] > 0:
    queue.append(entry)
  else:
    print("{} {}".format(entry[0], t))