#queueを使った方法
from collections import deque

pnum,mtime = map(int,input().split(" "))

q = deque([])
[q.append(input().split(" ")) for u in range(pnum)]

tcnt=0
while len(q) > 0:
	qq = q.popleft()
	ztime = int(qq[1]) - mtime
	if ztime <= 0:
		tcnt += int(qq[1])
		print(qq[0],int(tcnt))
	else:
		q.append([qq[0],ztime])
		tcnt += mtime
 from collections import deque pnum,mtime = map(int,input().split(" ")) pnum map(int,input().split(" ")) map int input().split(" ") ().split () input split " " mtime q = deque([]) q deque([]) deque [] q.append(input().split(" ")) for u in range(pnum) for u in range(pnum) u range(pnum) range pnum for u in range(pnum) q.append(input().split(" ")) q.append q append input().split(" ") ().split () input split " " [q.append(input().split(" ")) for u in range(pnum)] tcnt=0 tcnt 0 while len(q) > 0:
	qq = q.popleft()
	ztime = int(qq[1]) - mtime
	if ztime <= 0:
		tcnt += int(qq[1])
		print(qq[0],int(tcnt))
	else:
		q.append([qq[0],ztime])
		tcnt += mtime len(q) > 0 len(q) len q 0 qq = q.popleft() qq q.popleft() q.popleft q popleft ztime = int(qq[1]) - mtime ztime int(qq[1]) - mtime int(qq[1]) int qq[1] qq 1 mtime if ztime <= 0:
		tcnt += int(qq[1])
		print(qq[0],int(tcnt))
	else:
		q.append([qq[0],ztime])
		tcnt += mtime ztime <= 0 ztime 0 tcnt += int(qq[1]) tcnt int(qq[1]) int qq[1] qq 1 print(qq[0],int(tcnt)) print qq[0] qq 0 int(tcnt) int tcnt q.append([qq[0],ztime]) q.append q append [qq[0],ztime] qq[0] qq 0 ztime tcnt += mtime tcnt mtime tcnt=0 0 tcnt qq = q.popleft() q.popleft() qq pnum,mtime = map(int,input().split(" ")) map(int,input().split(" ")) pnum tcnt += int(qq[1]) int(qq[1]) tcnt mtime = map(int,input().split(" ")) map(int,input().split(" ")) mtime q = deque([]) deque([]) q ztime = int(qq[1]) - mtime int(qq[1]) - mtime ztime tcnt += mtime mtime tcnt
#queueを使った方法
from collections import deque

pnum,mtime = map(int,input().split(" "))

q = deque([])
[q.append(input().split(" ")) for u in range(pnum)]

tcnt=0
while len(q) > 0:
	qq = q.popleft()
	ztime = int(qq[1]) - mtime
	if ztime <= 0:
		tcnt += int(qq[1])
		print(qq[0],int(tcnt))
	else:
		q.append([qq[0],ztime])
		tcnt += mtime

