
class Node:
	def __init__(self, value):
		self.value = value
		self.next = None

class SimpleQeueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_

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())
myqueue = SimpleQeueue()
for i in range(n):
	name, time = map(str, input().split())
	myqueue.enqueue(Process(name, time))

time_elapsed = 0
while myqueue.is_empty() != True:
	process = myqueue.dequeue()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		myqueue.enqueue(process)
	else:
		time_elapsed += time
		print(process.name + ' ' + str(time_elapsed))
 class Node:
	def __init__(self, value):
		self.value = value
		self.next = None Node def __init__(self, value):
		self.value = value
		self.next = None __init__ self.value = value self.value self value value self.next = None self.next self next None self self value value class SimpleQeueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_ SimpleQeueue def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	 __init__ self.size = 0 self.size self size 0 self.head = None self.head self head None self.tail = None self.tail self tail None return self self def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	 enqueue node = Node(value) node Node(value) Node value if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		 self.head == None self.head self head None self.head = node self.head self head node self.tail = node self.tail self tail node self.tail.next = node self.tail.next self.tail self tail next node self.tail = node self.tail self tail node self.size += 1 self.size self size 1 self self value value def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	 dequeue if self.is_empty() == True:
			return None
		 self.is_empty() == True self.is_empty() self.is_empty self is_empty True return None None node = self.head node self.head self head self.head = self.head.next self.head self head self.head.next self.head self head next self.size -= 1 self.size self size 1 if self.is_empty() == True:
			self.head = None
			self.tail = None
		 self.is_empty() == True self.is_empty() self.is_empty self is_empty True self.head = None self.head self head None self.tail = None self.tail self tail None return node.value node.value node value self self def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	 peek if self.is_empty() == True:
			return None
		 self.is_empty() == True self.is_empty() self.is_empty self is_empty True return None None return self.head.value self.head.value self.head self head value self self def get_size(self):
		return self.size

	 get_size return self.size self.size self size self self def is_empty(self):
		return self.size == 0

	 is_empty return self.size == 0 self.size == 0 self.size self size 0 self self def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_ __str__ str_ = '[' str_ '[' current = self.head current self.head self head while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		 current != None current None str_ += str(current.value) str_ str(current.value) str current.value current value current = current.next current current.next current next if current != None:
				str_ += ', '
		 current != None current None str_ += ', ' str_ ', ' str_ += '][' str_ '][' if self.tail != None:
			str_ += str(self.tail.value)
		 self.tail != None self.tail self tail None str_ += str(self.tail.value) str_ str(self.tail.value) str self.tail.value self.tail self tail value str_ += ']' str_ ']' return str_ str_ self self 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 myqueue = SimpleQeueue() myqueue SimpleQeueue() SimpleQeueue for i in range(n):
	name, time = map(str, input().split())
	myqueue.enqueue(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 myqueue.enqueue(Process(name, time)) myqueue.enqueue myqueue enqueue Process(name, time) Process name time time_elapsed = 0 time_elapsed 0 while myqueue.is_empty() != True:
	process = myqueue.dequeue()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		myqueue.enqueue(process)
	else:
		time_elapsed += time
		print(process.name + ' ' + str(time_elapsed)) myqueue.is_empty() != True myqueue.is_empty() myqueue.is_empty myqueue is_empty True process = myqueue.dequeue() process myqueue.dequeue() myqueue.dequeue myqueue dequeue time = process.time time process.time process time if time > q:
		process.set_time(time - q)
		time_elapsed += q
		myqueue.enqueue(process)
	else:
		time_elapsed += time
		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 myqueue.enqueue(process) myqueue.enqueue myqueue enqueue process time_elapsed += time time_elapsed time print(process.name + ' ' + str(time_elapsed)) print process.name + ' ' + str(time_elapsed) process.name + ' ' process.name process name ' ' str(time_elapsed) str time_elapsed n, q = map(int, input().split()) map(int, input().split()) n time_elapsed += q q time_elapsed class SimpleQeueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_ class SimpleQeueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_ SimpleQeueue time_elapsed += time time time_elapsed time = map(str, input().split()) map(str, input().split()) time time = process.time process.time time q = map(int, input().split()) map(int, input().split()) q time_elapsed = 0 0 time_elapsed class Node:
	def __init__(self, value):
		self.value = value
		self.next = None class Node:
	def __init__(self, value):
		self.value = value
		self.next = None Node 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 = myqueue.dequeue() myqueue.dequeue() process name, time = map(str, input().split()) map(str, input().split()) name myqueue = SimpleQeueue() SimpleQeueue() myqueue

class Node:
	def __init__(self, value):
		self.value = value
		self.next = None

class SimpleQeueue:
	def __init__(self):
		self.size = 0
		self.head = None
		self.tail = None
		return

	def enqueue(self, value):
		node = Node(value)
		if self.head == None:
			self.head = node
			self.tail = node
		else:
			self.tail.next = node
			self.tail = node
		self.size += 1

	def dequeue(self):
		if self.is_empty() == True:
			return None
		node = self.head
		self.head = self.head.next
		self.size -= 1
		if self.is_empty() == True:
			self.head = None
			self.tail = None
		return node.value

	def peek(self):
		if self.is_empty() == True:
			return None
		return self.head.value

	def get_size(self):
		return self.size

	def is_empty(self):
		return self.size == 0

	def __str__(self):
		str_ = '['
		current = self.head
		while current != None:
			str_ += str(current.value)
			current = current.next
			if current != None:
				str_ += ', '
		str_ += ']['
		if self.tail != None:
			str_ += str(self.tail.value)
		str_ += ']'
		return str_

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())
myqueue = SimpleQeueue()
for i in range(n):
	name, time = map(str, input().split())
	myqueue.enqueue(Process(name, time))

time_elapsed = 0
while myqueue.is_empty() != True:
	process = myqueue.dequeue()
	time = process.time
	if time > q:
		process.set_time(time - q)
		time_elapsed += q
		myqueue.enqueue(process)
	else:
		time_elapsed += time
		print(process.name + ' ' + str(time_elapsed))

