#coding:UTF-8
def Queue(n,q,B):
    ans=[]
    ftime=0
    while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
    for i in range(n): 
        print(ans[i])
        
  
if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    q=int(a.split(" ")[1])
    B=[]
    for i in range(n):
        B.append(input())
    Queue(n,q,B) def Queue(n,q,B):
    ans=[]
    ftime=0
    while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
    for i in range(n): 
        print(ans[i])
        
   Queue ans=[] ans [] ftime=0 ftime 0 while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
     len(B)>0 len(B) len B 0 name=B[0].split(" ")[0] name B[0].split(" ")[0] [0].split(" ") [0].split [0] B 0 split " " 0 time=int(B[0].split(" ")[1]) time int(B[0].split(" ")[1]) int B[0].split(" ")[1] [0].split(" ") [0].split [0] B 0 split " " 1 if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
     time>q time q ftime+=q ftime q newB=name+" "+str(time-q) newB name+" "+str(time-q) name+" " name " " str(time-q) str time-q time q B.append(newB) B.append B append newB B.pop(0) B.pop B pop 0 ans.append(name+" "+str(ftime+time)) ans.append ans append name+" "+str(ftime+time) name+" " name " " str(ftime+time) str ftime+time ftime time B.pop(0) B.pop B pop 0 ftime+=time ftime time for i in range(n): 
        print(ans[i])
        
   i range(n) range n print(ans[i]) print ans[i] ans i n n q q B B if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    q=int(a.split(" ")[1])
    B=[]
    for i in range(n):
        B.append(input())
    Queue(n,q,B) __name__=="__main__" __name__ "__main__" a=input() a input() input n=int(a.split(" ")[0]) n int(a.split(" ")[0]) int a.split(" ")[0] a.split(" ") a.split a split " " 0 q=int(a.split(" ")[1]) q int(a.split(" ")[1]) int a.split(" ")[1] a.split(" ") a.split a split " " 1 B=[] B [] for i in range(n):
        B.append(input())
     i range(n) range n B.append(input()) B.append B append input() input Queue(n,q,B) Queue n q B a=input() input() a n=int(a.split(" ")[0]) int(a.split(" ")[0]) n B=[] [] B q=int(a.split(" ")[1]) int(a.split(" ")[1]) q def Queue(n,q,B):
    ans=[]
    ftime=0
    while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
    for i in range(n): 
        print(ans[i])
        
   def Queue(n,q,B):
    ans=[]
    ftime=0
    while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
    for i in range(n): 
        print(ans[i])
        
   Queue
#coding:UTF-8
def Queue(n,q,B):
    ans=[]
    ftime=0
    while len(B)>0:
        name=B[0].split(" ")[0]
        time=int(B[0].split(" ")[1])
        if time>q:
            ftime+=q
            newB=name+" "+str(time-q)
            B.append(newB)
            B.pop(0)
        else :
            ans.append(name+" "+str(ftime+time))
            B.pop(0)
            ftime+=time
    for i in range(n): 
        print(ans[i])
        
  
if __name__=="__main__":
    a=input()
    n=int(a.split(" ")[0])
    q=int(a.split(" ")[1])
    B=[]
    for i in range(n):
        B.append(input())
    Queue(n,q,B)