

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



total = [list(input().split(" ")) for _ in range(pnum)]



cnt=0

tcnt=0

while len(total) > 0:

	ztime = int(total[0][1]) - mtime

	if ztime <= 0:

		tcnt += int(total[0][1])

		print((total[0][0],int(tcnt)))

		total.pop(0)

	else:

		total.append([total[0][0],ztime])

		total.pop(0)

		tcnt += mtime

	cnt += 1



#queueを使った方法

from collections import deque



pnum,mtime = list(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



pnum, mtime = list(map(int, input().split(" ")))
total = [list(input().split(" ")) for _ in range(pnum)]
cnt = 0
tcnt = 0
while len(total) > 0:
    ztime = int(total[0][1]) - mtime
    if ztime <= 0:
        tcnt += int(total[0][1])
        print((total[0][0], int(tcnt)))
        total.pop(0)
    else:
        total.append([total[0][0], ztime])
        total.pop(0)
        tcnt += mtime
    cnt += 1

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

pnum, mtime = list(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

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