from queue import Queue

class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time

n, q = map(int, input().split())
queue = Queue()
for i in range(n):
	name, time = map(str, input().split())
	queue.put(Process(name, time))

time_elapsed = 0
while queue.empty() != True:
	process = queue.get()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += min(time, q)
		print(process.name + ' ' + str(time_elapsed)) from queue import Queue class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time Process def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	 __init__ self.name = name self.name self name name self.time = int(time) self.time self time int(time) int time self self name name time time def set_time(self, time):
		self.time = time set_time self.time = time self.time self time time self self time time n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = Queue() queue Queue() Queue for i in range(n):
	name, time = map(str, input().split())
	queue.put(Process(name, time)) i range(n) range n name, time = map(str, input().split()) name map(str, input().split()) map str input().split() ().split () input split time queue.put(Process(name, time)) queue.put queue put Process(name, time) Process name time time_elapsed = 0 time_elapsed 0 while queue.empty() != True:
	process = queue.get()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += min(time, q)
		print(process.name + ' ' + str(time_elapsed)) queue.empty() != True queue.empty() queue.empty queue empty True process = queue.get() process queue.get() queue.get queue get time = process.time time process.time process time if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += min(time, q)
		print(process.name + ' ' + str(time_elapsed)) time > q time q process.set_time(time - q) process.set_time process set_time time - q time q time_elapsed += q time_elapsed q queue.put(process) queue.put queue put process time_elapsed += min(time, q) time_elapsed min(time, q) min time q print(process.name + ' ' + str(time_elapsed)) print process.name + ' ' + str(time_elapsed) process.name + ' ' process.name process name ' ' str(time_elapsed) str time_elapsed time = map(str, input().split()) map(str, input().split()) time queue = Queue() Queue() queue q = map(int, input().split()) map(int, input().split()) q time_elapsed += q q time_elapsed time_elapsed += min(time, q) min(time, q) time_elapsed class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time Process process = queue.get() queue.get() process time_elapsed = 0 0 time_elapsed n, q = map(int, input().split()) map(int, input().split()) n name, time = map(str, input().split()) map(str, input().split()) name time = process.time process.time time
from queue import Queue

class Process:
	def __init__(self, name, time):
		self.name = name
		self.time = int(time)

	def set_time(self, time):
		self.time = time

n, q = map(int, input().split())
queue = Queue()
for i in range(n):
	name, time = map(str, input().split())
	queue.put(Process(name, time))

time_elapsed = 0
while queue.empty() != True:
	process = queue.get()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		queue.put(process)
	else:
		time_elapsed += min(time, q)
		print(process.name + ' ' + str(time_elapsed))
