#----------------for input------------------------
numberAndQuontum=input().split()
number=int(numberAndQuontum[0])
Quontum=int(numberAndQuontum[1])
allProcessList=[]

index=0
while index<number:
    nameAndTime=input().split()
    nameTimeList=[]
    nameTimeList.append(nameAndTime[0])
    nameTimeList.append(int(nameAndTime[1]))
    allProcessList.append(nameTimeList)
    index+=1
#----------------for input------------------------

def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main---------------------------
schedule(Quontum,allProcessList)

            
 numberAndQuontum=input().split() numberAndQuontum input().split() ().split () input split number=int(numberAndQuontum[0]) number int(numberAndQuontum[0]) int numberAndQuontum[0] numberAndQuontum 0 Quontum=int(numberAndQuontum[1]) Quontum int(numberAndQuontum[1]) int numberAndQuontum[1] numberAndQuontum 1 allProcessList=[] allProcessList [] index=0 index 0 while index<number:
    nameAndTime=input().split()
    nameTimeList=[]
    nameTimeList.append(nameAndTime[0])
    nameTimeList.append(int(nameAndTime[1]))
    allProcessList.append(nameTimeList)
    index+=1
#----------------for input------------------------ index<number index number nameAndTime=input().split() nameAndTime input().split() ().split () input split nameTimeList=[] nameTimeList [] nameTimeList.append(nameAndTime[0]) nameTimeList.append nameTimeList append nameAndTime[0] nameAndTime 0 nameTimeList.append(int(nameAndTime[1])) nameTimeList.append nameTimeList append int(nameAndTime[1]) int nameAndTime[1] nameAndTime 1 allProcessList.append(nameTimeList) allProcessList.append allProcessList append nameTimeList index+=1 index 1 def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main--------------------------- schedule time=0 time 0 listForReturn=[] listForReturn [] while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
     True index=0 index 0 if allProcessList==[]:
            break
         allProcessList==[] allProcessList [] break length=len(allProcessList) length len(allProcessList) len allProcessList while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
         index<length index length if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
         allProcessList[index][1]<=Quontum allProcessList[index][1] [index] allProcessList index 1 Quontum time+=allProcessList[index][1] time allProcessList[index][1] [index] allProcessList index 1 listForReturn.append(allProcessList[index][0]+" "+str(time)) listForReturn.append listForReturn append allProcessList[index][0]+" "+str(time) allProcessList[index][0]+" " allProcessList[index][0] [index] allProcessList index 0 " " str(time) str time allProcessList[index]=[] allProcessList[index] allProcessList index [] index+=1 index 1 time+=Quontum time Quontum listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum] listForAppend [allProcessList[index][0],allProcessList[index][1]-Quontum] allProcessList[index][0] [index] allProcessList index 0 allProcessList[index][1]-Quontum allProcessList[index][1] [index] allProcessList index 1 Quontum allProcessList.append(listForAppend) allProcessList.append allProcessList append listForAppend allProcessList[index]=[] allProcessList[index] allProcessList index [] index+=1 index 1 while [] in allProcessList:
            allProcessList.remove([])
     [] in allProcessList [] allProcessList allProcessList.remove([]) allProcessList.remove allProcessList remove [] for printPair in listForReturn:
        print(printPair)

#-------------------for main--------------------------- printPair listForReturn print(printPair) print printPair Quontum Quontum allProcessList allProcessList schedule(Quontum,allProcessList) schedule Quontum allProcessList Quontum=int(numberAndQuontum[1]) int(numberAndQuontum[1]) Quontum nameAndTime=input().split() input().split() nameAndTime numberAndQuontum=input().split() input().split() numberAndQuontum def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main--------------------------- def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main--------------------------- schedule index=0 0 index allProcessList=[] [] allProcessList number=int(numberAndQuontum[0]) int(numberAndQuontum[0]) number index+=1 1 index nameTimeList=[] [] nameTimeList
#----------------for input------------------------
numberAndQuontum=input().split()
number=int(numberAndQuontum[0])
Quontum=int(numberAndQuontum[1])
allProcessList=[]

index=0
while index<number:
    nameAndTime=input().split()
    nameTimeList=[]
    nameTimeList.append(nameAndTime[0])
    nameTimeList.append(int(nameAndTime[1]))
    allProcessList.append(nameTimeList)
    index+=1
#----------------for input------------------------

def schedule(Quontum,allProcessList):
    time=0
    listForReturn=[]
    while True:
        index=0
        if allProcessList==[]:
            break
        length=len(allProcessList)
        while index<length:
            if allProcessList[index][1]<=Quontum:
                time+=allProcessList[index][1]
                listForReturn.append(allProcessList[index][0]+" "+str(time))
                allProcessList[index]=[]
                index+=1
            else:
                time+=Quontum
                listForAppend=[allProcessList[index][0],allProcessList[index][1]-Quontum]
                allProcessList.append(listForAppend)
                allProcessList[index]=[]
                index+=1
        while [] in allProcessList:
            allProcessList.remove([])
    for printPair in listForReturn:
        print(printPair)

#-------------------for main---------------------------
schedule(Quontum,allProcessList)

            

