n,q = map(int,raw_input().split())
task = []
lst = []
a = 0
for i in range(n):
    name,time = raw_input().split()
    task.append(int(time))
    lst.append(name)
while True:
	if task[0] > q:
		task[0] = task[0] - q
		task.append(task.pop(0))
		lst.append(lst.pop(0))
		a += q
	else:
		a += task[0]
		print lst[0],a
		task.pop(0)
		lst.pop(0)
		if len(lst) == 0:
			break n,q = map(int,raw_input().split()) n map(int,raw_input().split()) map int raw_input().split() ().split () raw_input split q task = [] task [] lst = [] lst [] a = 0 a 0 for i in range(n):
    name,time = raw_input().split()
    task.append(int(time))
    lst.append(name) i range(n) range n name,time = raw_input().split() name raw_input().split() ().split () raw_input split time task.append(int(time)) task.append task append int(time) int time lst.append(name) lst.append lst append name while True:
	if task[0] > q:
		task[0] = task[0] - q
		task.append(task.pop(0))
		lst.append(lst.pop(0))
		a += q
	else:
		a += task[0]
		print lst[0],a
		task.pop(0)
		lst.pop(0)
		if len(lst) == 0:
			break True if task[0] > q:
		task[0] = task[0] - q
		task.append(task.pop(0))
		lst.append(lst.pop(0))
		a += q
	else:
		a += task[0]
		print lst[0],a
		task.pop(0)
		lst.pop(0)
		if len(lst) == 0:
			break task[0] > q task[0] task 0 q task[0] = task[0] - q task[0] task 0 task[0] - q task[0] task 0 q task.append(task.pop(0)) task.append task append task.pop(0) task.pop task pop 0 lst.append(lst.pop(0)) lst.append lst append lst.pop(0) lst.pop lst pop 0 a += q a q a += task[0] a task[0] task 0 print lst[0] lst 0 a task.pop(0) task.pop task pop 0 lst.pop(0) lst.pop lst pop 0 if len(lst) == 0:
			break len(lst) == 0 len(lst) len lst 0 break n,q = map(int,raw_input().split()) map(int,raw_input().split()) n a += task[0] task[0] a name,time = raw_input().split() raw_input().split() name task = [] [] task time = raw_input().split() raw_input().split() time a += q q a q = map(int,raw_input().split()) map(int,raw_input().split()) q lst = [] [] lst a = 0 0 a
n,q = map(int,raw_input().split())
task = []
lst = []
a = 0
for i in range(n):
    name,time = raw_input().split()
    task.append(int(time))
    lst.append(name)
while True:
	if task[0] > q:
		task[0] = task[0] - q
		task.append(task.pop(0))
		lst.append(lst.pop(0))
		a += q
	else:
		a += task[0]
		print lst[0],a
		task.pop(0)
		lst.pop(0)
		if len(lst) == 0:
			break