class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
    
class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val()

s = input()
n,limit=map(int,s.split())
que=Queue()
for i in range(n):
    lis=input().split()
    que.enqueue((lis[0],int(lis[1])))

time=0
while(True):
    elm=que.dequeue()
    if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=limit
    else:
        time+=elm[1]
        print(elm[0],time) class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
     Trio __pre=None __pre None __val=None __val None __nex=None __nex None def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
     __init__ self.__pre=p self.__pre self __pre p self.__val=val self.__val self __val val self.__nex=n self.__nex self __nex n self self val val p=None p None n=None n None def get_pre(self):return self.__pre
    
     get_pre self self def get_nex(self):return self.__nex
    
     get_nex self self def set_pre(self,n):self.__pre=n
        
     set_pre self self n n def set_nex(self,n):self.__nex=n
    
     set_nex self self n n def set_val(self,n):self.__val=n
    
     set_val self self n n def get_val(self):return self.__val
     get_val self self class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val() Queue top = back = None top None = back = None back None def __init__(self):
        pass
    
     __init__ self self def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
     enqueue if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
     self.top==None self.top self top None self.top = self.back = Trio(n) self.top self top Trio(n) Trio n = self.back = Trio(n) self.back self back Trio(n) self.back.set_nex(Trio(n,p=self.back)) self.back.set_nex self.back self back set_nex Trio(n,p=self.back) Trio n p=self.back p self.back self back self.back=self.back.get_nex() self.back self back self.back.get_nex() self.back.get_nex self.back self back get_nex self self n n def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val() dequeue if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val() self.top==None self.top self top None return None None elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
         self.top==self.back self.top self top self.back self back a=self.top.get_val() a self.top.get_val() self.top.get_val self.top self top get_val self.top,self.back=None,None self.top self top None self.back self back None return a a self.top=self.top.get_nex() self.top self top self.top.get_nex() self.top.get_nex self.top self top get_nex oldtop=self.top.get_pre() oldtop self.top.get_pre() self.top.get_pre self.top self top get_pre self.top.set_pre(None) self.top.set_pre self.top self top set_pre None return oldtop.get_val() oldtop.get_val() oldtop.get_val oldtop get_val self self s = input() s input() input n,limit=map(int,s.split()) n map(int,s.split()) map int s.split() s.split s split limit que=Queue() que Queue() Queue for i in range(n):
    lis=input().split()
    que.enqueue((lis[0],int(lis[1]))) i range(n) range n lis=input().split() lis input().split() ().split () input split que.enqueue((lis[0],int(lis[1]))) que.enqueue que enqueue (lis[0],int(lis[1])) lis[0] lis 0 int(lis[1]) int lis[1] lis 1 time=0 time 0 while(True):
    elm=que.dequeue()
    if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=limit
    else:
        time+=elm[1]
        print(elm[0],time) True elm=que.dequeue() elm que.dequeue() que.dequeue que dequeue if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=limit
    else:
        time+=elm[1]
        print(elm[0],time) elm==None elm None break elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=limit
     elm[1]>limit elm[1] elm 1 limit que.enqueue((elm[0],elm[1]-limit)) que.enqueue que enqueue (elm[0],elm[1]-limit) elm[0] elm 0 elm[1]-limit elm[1] elm 1 limit time+=limit time limit time+=elm[1] time elm[1] elm 1 print(elm[0],time) print elm[0] elm 0 time time+=limit limit time elm=que.dequeue() que.dequeue() elm class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
     class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
     Trio limit=map(int,s.split()) map(int,s.split()) limit n,limit=map(int,s.split()) map(int,s.split()) n lis=input().split() input().split() lis time+=elm[1] elm[1] time que=Queue() Queue() que time=0 0 time s = input() input() s class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val() class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val() Queue
class Trio:
    __pre=None
    __val=None
    __nex=None
    def __init__(self,val,p=None,n=None):
        self.__pre=p
        self.__val=val
        self.__nex=n
    
    def get_pre(self):return self.__pre
    
    def get_nex(self):return self.__nex
    
    def set_pre(self,n):self.__pre=n
        
    def set_nex(self,n):self.__nex=n
    
    def set_val(self,n):self.__val=n
    
    def get_val(self):return self.__val
    
class Queue:
    top = back = None
    def __init__(self):
        pass
    
    def enqueue(self,n):
        if(self.top==None):
            self.top = self.back = Trio(n)
        else:
            self.back.set_nex(Trio(n,p=self.back))
            self.back=self.back.get_nex()
    
    def dequeue(self):
        if(self.top==None):
            return None
        elif(self.top==self.back):
            a=self.top.get_val()
            self.top,self.back=None,None
            return a
        else:
            self.top=self.top.get_nex()
            oldtop=self.top.get_pre()
            self.top.set_pre(None)
            return oldtop.get_val()

s = input()
n,limit=map(int,s.split())
que=Queue()
for i in range(n):
    lis=input().split()
    que.enqueue((lis[0],int(lis[1])))

time=0
while(True):
    elm=que.dequeue()
    if(elm==None):
        break
    elif(elm[1]>limit):
        que.enqueue((elm[0],elm[1]-limit))
        time+=limit
    else:
        time+=elm[1]
        print(elm[0],time)