from collections import deque

def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head)

if __name__ == '__main__':
	n, q = map(int, input().split())
	A = deque()

	for i in range(n):
		name, time = input().split()
		A.append([name, int(time)])
	
	round_robin_scheduling(n, q, A) from collections import deque def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head) round_robin_scheduling sum = 0 sum 0 while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head) A head = A.popleft() head A.popleft() A.popleft A popleft if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head) head[1] <= q head[1] head 1 q sum += head[1] sum head[1] head 1 print(head[0], sum) print head[0] head 0 sum sum += q sum q head[1] -= q head[1] head 1 q A.append(head) A.append A append head n n q q A A if __name__ == '__main__':
	n, q = map(int, input().split())
	A = deque()

	for i in range(n):
		name, time = input().split()
		A.append([name, int(time)])
	
	round_robin_scheduling(n, q, A) __name__ == '__main__' __name__ '__main__' n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q A = deque() A deque() deque for i in range(n):
		name, time = input().split()
		A.append([name, int(time)])
	
	 i range(n) range n name, time = input().split() name input().split() ().split () input split time A.append([name, int(time)]) A.append A append [name, int(time)] name int(time) int time round_robin_scheduling(n, q, A) round_robin_scheduling n q A q = map(int, input().split()) map(int, input().split()) q name, time = input().split() input().split() name n, q = map(int, input().split()) map(int, input().split()) n A = deque() deque() A def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head) def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head) round_robin_scheduling time = input().split() input().split() time
from collections import deque

def round_robin_scheduling(n, q, A):
	sum = 0

	while A:
		head = A.popleft()
		if head[1] <= q:
			sum += head[1]
			print(head[0], sum)
		else:
			sum += q
			head[1] -= q
			A.append(head)

if __name__ == '__main__':
	n, q = map(int, input().split())
	A = deque()

	for i in range(n):
		name, time = input().split()
		A.append([name, int(time)])
	
	round_robin_scheduling(n, q, A)