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

t = 0
i = 0
while queue:
	i %= len(queue)
	p = queue[i]
	t += min(q, p[1])
	if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i) n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q queue = [] queue [] for i in range(n):
	name,time = input().split()
	queue.append([name, int(time)]) i range(n) range n name,time = input().split() name input().split() ().split () input split time queue.append([name, int(time)]) queue.append queue append [name, int(time)] name int(time) int time t = 0 t 0 i = 0 i 0 while queue:
	i %= len(queue)
	p = queue[i]
	t += min(q, p[1])
	if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i) queue i %= len(queue) i len(queue) len queue p = queue[i] p queue[i] queue i t += min(q, p[1]) t min(q, p[1]) min q p[1] p 1 if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i) p[1] > q p[1] p 1 q p[1] -= q p[1] p 1 q i += 1 i 1 print(p[0], t) print p[0] p 0 t queue.pop(i) queue.pop queue pop i t = 0 0 t n,q = map(int,input().split()) map(int,input().split()) n p = queue[i] queue[i] p i %= len(queue) len(queue) i time = input().split() input().split() time i = 0 0 i i += 1 1 i q = map(int,input().split()) map(int,input().split()) q name,time = input().split() input().split() name t += min(q, p[1]) min(q, p[1]) t queue = [] [] queue
n,q = map(int,input().split())
queue = []
for i in range(n):
	name,time = input().split()
	queue.append([name, int(time)])

t = 0
i = 0
while queue:
	i %= len(queue)
	p = queue[i]
	t += min(q, p[1])
	if p[1] > q:
		p[1] -= q
		i += 1
	else:
		print(p[0], t)
		queue.pop(i)
