from queue import Queue
n,q = map(int,input().split())
names = []
times = []
for _ in range(n):
  data = list(map(str,input().split()))
  names.append(data[0])
  times.append(int(data[1]))

names_queue = Queue()
times_queue = Queue()
for i in range(n):
  names_queue.put(names[i])
  times_queue.put(times[i])
#print("---------")
time = 0
i = 0
ret = {}
while True:
  if times_queue.empty():
    break
  d = times_queue.get()
  n = names_queue.get()
# print("%s %d" %(n,d))
# print(d)
  if d-q <= 0:
    time += d
    ret[n] = time
  else:
    times_queue.put(d-q)
    names_queue.put(n)
    time += q
#print("--------")
for key,value in ret.items():
  print("%s %d" %(key,value))
 from queue import Queue n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q names = [] names [] times = [] times [] for _ in range(n):
  data = list(map(str,input().split()))
  names.append(data[0])
  times.append(int(data[1])) _ range(n) range n data = list(map(str,input().split())) data list(map(str,input().split())) list map(str,input().split()) map str input().split() ().split () input split names.append(data[0]) names.append names append data[0] data 0 times.append(int(data[1])) times.append times append int(data[1]) int data[1] data 1 names_queue = Queue() names_queue Queue() Queue times_queue = Queue() times_queue Queue() Queue for i in range(n):
  names_queue.put(names[i])
  times_queue.put(times[i])
#print("---------") i range(n) range n names_queue.put(names[i]) names_queue.put names_queue put names[i] names i times_queue.put(times[i]) times_queue.put times_queue put times[i] times i time = 0 time 0 i = 0 i 0 ret = {} ret {} while True:
  if times_queue.empty():
    break
  d = times_queue.get()
  n = names_queue.get()
# print("%s %d" %(n,d))
# print(d)
  if d-q <= 0:
    time += d
    ret[n] = time
  else:
    times_queue.put(d-q)
    names_queue.put(n)
    time += q
#print("--------") True if times_queue.empty():
    break
   times_queue.empty() times_queue.empty times_queue empty break d = times_queue.get() d times_queue.get() times_queue.get times_queue get n = names_queue.get() n names_queue.get() names_queue.get names_queue get if d-q <= 0:
    time += d
    ret[n] = time
  else:
    times_queue.put(d-q)
    names_queue.put(n)
    time += q
#print("--------") d-q <= 0 d-q d q 0 time += d time d ret[n] = time ret[n] ret n time times_queue.put(d-q) times_queue.put times_queue put d-q d q names_queue.put(n) names_queue.put names_queue put n time += q time q for key,value in ret.items():
  print("%s %d" %(key,value)) key value ret.items() ret.items ret items print("%s %d" %(key,value)) print "%s %d" %(key,value) "%s %d" (key,value) key value n,q = map(int,input().split()) map(int,input().split()) n time += q q time data = list(map(str,input().split())) list(map(str,input().split())) data d = times_queue.get() times_queue.get() d times = [] [] times times_queue = Queue() Queue() times_queue names_queue = Queue() Queue() names_queue q = map(int,input().split()) map(int,input().split()) q names = [] [] names time += d d time time = 0 0 time i = 0 0 i n = names_queue.get() names_queue.get() n ret = {} {} ret
from queue import Queue
n,q = map(int,input().split())
names = []
times = []
for _ in range(n):
  data = list(map(str,input().split()))
  names.append(data[0])
  times.append(int(data[1]))

names_queue = Queue()
times_queue = Queue()
for i in range(n):
  names_queue.put(names[i])
  times_queue.put(times[i])
#print("---------")
time = 0
i = 0
ret = {}
while True:
  if times_queue.empty():
    break
  d = times_queue.get()
  n = names_queue.get()
# print("%s %d" %(n,d))
# print(d)
  if d-q <= 0:
    time += d
    ret[n] = time
  else:
    times_queue.put(d-q)
    names_queue.put(n)
    time += q
#print("--------")
for key,value in ret.items():
  print("%s %d" %(key,value))

