#ALDS_3_B 16D8103010K Ko Okasaki

from collections import deque

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

t=0

while len(que)>0:
    que_t=que.popleft()
    if que_t[1]>q:
        que_t[1]-=q
        t+=q
        que.append(que_t)
    else:
        t+=que_t[1]
        print(que_t[0],t) from collections import deque n,q=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q que=deque() que deque() deque for i in range(n):
   name,time=input().split()
   time=int(time)
   que.append([name,time]) i range(n) range n name,time=input().split() name input().split() ().split () input split time time=int(time) time int(time) int time que.append([name,time]) que.append que append [name,time] name time t=0 t 0 while len(que)>0:
    que_t=que.popleft()
    if que_t[1]>q:
        que_t[1]-=q
        t+=q
        que.append(que_t)
    else:
        t+=que_t[1]
        print(que_t[0],t) len(que)>0 len(que) len que 0 que_t=que.popleft() que_t que.popleft() que.popleft que popleft if que_t[1]>q:
        que_t[1]-=q
        t+=q
        que.append(que_t)
    else:
        t+=que_t[1]
        print(que_t[0],t) que_t[1]>q que_t[1] que_t 1 q que_t[1]-=q que_t[1] que_t 1 q t+=q t q que.append(que_t) que.append que append que_t t+=que_t[1] t que_t[1] que_t 1 print(que_t[0],t) print que_t[0] que_t 0 t que=deque() deque() que t=0 0 t q=map(int,input().split()) map(int,input().split()) q que_t=que.popleft() que.popleft() que_t n,q=map(int,input().split()) map(int,input().split()) n name,time=input().split() input().split() name t+=q q t time=int(time) int(time) time time=input().split() input().split() time t+=que_t[1] que_t[1] t
#ALDS_3_B 16D8103010K Ko Okasaki

from collections import deque

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

t=0

while len(que)>0:
    que_t=que.popleft()
    if que_t[1]>q:
        que_t[1]-=q
        t+=q
        que.append(que_t)
    else:
        t+=que_t[1]
        print(que_t[0],t)
