# coding: utf-8
import sys
import collections

def main():
	n, quantum = map(int, raw_input().split())
	processes = [x.split() for x in sys.stdin.readlines()]
	for p in processes:
		p[1] = int(p[1])
	queue = collections.deque(processes)
	elapsed = 0
	while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed

if __name__ == '__main__':
	main() import sys sys import collections collections def main():
	n, quantum = map(int, raw_input().split())
	processes = [x.split() for x in sys.stdin.readlines()]
	for p in processes:
		p[1] = int(p[1])
	queue = collections.deque(processes)
	elapsed = 0
	while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed main n, quantum = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split quantum x.split() for x in sys.stdin.readlines() for x in sys.stdin.readlines() x sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for x in sys.stdin.readlines() x.split() x.split x split processes = [x.split() for x in sys.stdin.readlines()] processes [x.split() for x in sys.stdin.readlines()] for p in processes:
		p[1] = int(p[1])
	 p processes p[1] = int(p[1]) p[1] p 1 int(p[1]) int p[1] p 1 queue = collections.deque(processes) queue collections.deque(processes) collections.deque collections deque processes elapsed = 0 elapsed 0 while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed queue head = queue.popleft() head queue.popleft() queue.popleft queue popleft if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed head[1] > quantum head[1] head 1 quantum head[1] -= quantum head[1] head 1 quantum queue.append(head) queue.append queue append head elapsed += quantum elapsed quantum elapsed += head[1] elapsed head[1] head 1 print head[0] head 0 elapsed if __name__ == '__main__':
	main() __name__ == '__main__' __name__ '__main__' main() main def main():
	n, quantum = map(int, raw_input().split())
	processes = [x.split() for x in sys.stdin.readlines()]
	for p in processes:
		p[1] = int(p[1])
	queue = collections.deque(processes)
	elapsed = 0
	while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed def main():
	n, quantum = map(int, raw_input().split())
	processes = [x.split() for x in sys.stdin.readlines()]
	for p in processes:
		p[1] = int(p[1])
	queue = collections.deque(processes)
	elapsed = 0
	while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed main
# coding: utf-8
import sys
import collections

def main():
	n, quantum = map(int, raw_input().split())
	processes = [x.split() for x in sys.stdin.readlines()]
	for p in processes:
		p[1] = int(p[1])
	queue = collections.deque(processes)
	elapsed = 0
	while queue:
		# print elapsed, queue
		head = queue.popleft()
		if head[1] > quantum:
			head[1] -= quantum
			queue.append(head)
			elapsed += quantum
		else:
			elapsed += head[1]
			print head[0], elapsed

if __name__ == '__main__':
	main()