def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime



if __name__ == '__main__':
	N, sec = input().split()
	N, sec = int(N), int(sec)
	lists = list()

	for i in range(N):
		obj, times = input().split()
		lists.append([obj, int(times)])

	now = 0
	while lists:
		lists, now = Queue(lists, now, sec) def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime Queue if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime len(l) == 1 len(l) len l 1 print(l[0][0], nowtime + l[0][1]) print l[0][0] [0] l 0 0 nowtime + l[0][1] nowtime l[0][1] [0] l 0 1 return [], 0 return [], 0 [] 0 tl = l.pop(0) tl l.pop(0) l.pop l pop 0 if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime tl[1] <= sec tl[1] tl 1 sec nowtime += tl[1] nowtime tl[1] tl 1 print(tl[0], nowtime) print tl[0] tl 0 nowtime return l, nowtime return l, nowtime l nowtime nowtime += sec nowtime sec l.append([tl[0], tl[1] - sec]) l.append l append [tl[0], tl[1] - sec] tl[0] tl 0 tl[1] - sec tl[1] tl 1 sec return l, nowtime return l, nowtime l nowtime l l nowtime nowtime sec sec if __name__ == '__main__':
	N, sec = input().split()
	N, sec = int(N), int(sec)
	lists = list()

	for i in range(N):
		obj, times = input().split()
		lists.append([obj, int(times)])

	now = 0
	while lists:
		lists, now = Queue(lists, now, sec) __name__ == '__main__' __name__ '__main__' N, sec = input().split() N input().split() ().split () input split sec N, sec = int(N), int(sec) N int(N) int N sec int(sec) int sec lists = list() lists list() list for i in range(N):
		obj, times = input().split()
		lists.append([obj, int(times)])

	 i range(N) range N obj, times = input().split() obj input().split() ().split () input split times lists.append([obj, int(times)]) lists.append lists append [obj, int(times)] obj int(times) int times now = 0 now 0 while lists:
		lists, now = Queue(lists, now, sec) lists lists, now = Queue(lists, now, sec) lists Queue(lists, now, sec) Queue lists now sec now obj, times = input().split() input().split() obj sec = int(N), int(sec) int(sec) sec lists = list() list() lists lists, now = Queue(lists, now, sec) Queue(lists, now, sec) lists N, sec = input().split() input().split() N sec = input().split() input().split() sec times = input().split() input().split() times now = 0 0 now def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime Queue now = Queue(lists, now, sec) Queue(lists, now, sec) now N, sec = int(N), int(sec) int(N) N
def Queue(l, nowtime, sec):
	if len(l) == 1:
		print(l[0][0], nowtime + l[0][1])
		return [], 0

	else:
		tl = l.pop(0)

		if tl[1] <= sec:
			nowtime += tl[1]
			print(tl[0], nowtime)
			return l, nowtime

		else:
			nowtime += sec
			l.append([tl[0], tl[1] - sec])
			return l, nowtime



if __name__ == '__main__':
	N, sec = input().split()
	N, sec = int(N), int(sec)
	lists = list()

	for i in range(N):
		obj, times = input().split()
		lists.append([obj, int(times)])

	now = 0
	while lists:
		lists, now = Queue(lists, now, sec)
