#!/usr/bin/env python
#-*- coding:utf-8 -*-
from collections import deque

def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task

def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test():

if __name__ == '__main__':
	main()
	#test() from collections import deque def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task process_task exe_task = task.popleft() exe_task task.popleft() task.popleft task popleft t = int(exe_task[1]) t int(exe_task[1]) int exe_task[1] exe_task 1 q = int(qua) q int(qua) int qua if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	 t-q  > 0 t-q t q 0 exe_task[1] = (t - q) exe_task[1] exe_task 1 t - q t q task.append(exe_task) task.append task append exe_task elapsed_time += q elapsed_time q elapsed_time += t elapsed_time t complete_task.append([exe_task[0], elapsed_time]) complete_task.append complete_task append [exe_task[0], elapsed_time] exe_task[0] exe_task 0 elapsed_time return elapsed_time,complete_task return elapsed_time,complete_task elapsed_time complete_task task task qua qua elapsed_time elapsed_time complete_task complete_task def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test(): main n,q = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q raw_input().split() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) raw_input().split() ().split () raw_input split task = [raw_input().split() for _ in range(n)] task [raw_input().split() for _ in range(n)] que = deque(task) que deque(task) deque task ela_time = 0 ela_time 0 comp_task = [] comp_task [] while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	 len(que) != 0 len(que) len que 0 ela_time , comp_task= process_task(que, q, ela_time,comp_task) ela_time process_task(que, q, ela_time,comp_task) process_task que q ela_time comp_task comp_task for i in comp_task:
		print i[0], i[1]

#def test(): i comp_task print i[0] i 0 i[1] i 1 if __name__ == '__main__':
	main()
	#test() __name__ == '__main__' __name__ '__main__' main() main def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test(): def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test(): main def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task process_task
#!/usr/bin/env python
#-*- coding:utf-8 -*-
from collections import deque

def process_task(task,qua, elapsed_time, complete_task):
	exe_task = task.popleft()
	t = int(exe_task[1])
	q = int(qua)

	if t-q  > 0:
		exe_task[1] = (t - q)
		task.append(exe_task)
		elapsed_time += q
	else:	
		elapsed_time += t
		complete_task.append([exe_task[0], elapsed_time])

	return elapsed_time,complete_task

def main():
	n,q = map(int, raw_input().split())
	task = [raw_input().split() for _ in range(n)]
	que = deque(task)
	ela_time = 0
	comp_task = []

	while len(que) != 0:
		ela_time , comp_task= process_task(que, q, ela_time,comp_task)	

	for i in comp_task:
		print i[0], i[1]

#def test():

if __name__ == '__main__':
	main()
	#test()