# coding: utf-8
# Here your code !
import sys
from collections import deque

class CPU():
    def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
    def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

    def makeLog(self, in_process):
        print(in_process, self.total_time)

    
processes = deque()
times = deque()
    
data_cnt, quantum =  list(map(int,input().split(" ")))  

for i in range(data_cnt):
    tmp_process, tmp_time = input().split(" ")
    processes.append(tmp_process)
    times.append(int(tmp_time))

objCPU = CPU(quantum)

while True:
    processes, times = objCPU.deal(processes, times)
    if len(processes) == 0:
        break import sys sys from collections import deque class CPU():
    def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
    def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

    def makeLog(self, in_process):
        print(in_process, self.total_time)

     CPU def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
     __init__ self.quantum = in_quantum self.quantum self quantum in_quantum self.total_time = 0 self.total_time self total_time 0 self self in_quantum in_quantum def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

     deal this_process_time = 0 this_process_time 0 if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

         in_time[0] > self.quantum in_time[0] in_time 0 self.quantum self quantum remain_time = in_time[0] - self.quantum remain_time in_time[0] - self.quantum in_time[0] in_time 0 self.quantum self quantum this_process_time = in_time[0] - remain_time this_process_time in_time[0] - remain_time in_time[0] in_time 0 remain_time in_process.append(in_process[0]) in_process.append in_process append in_process[0] in_process 0 in_time.append(remain_time) in_time.append in_time append remain_time self.total_time += this_process_time self.total_time self total_time this_process_time this_process_time = in_time[0] this_process_time in_time[0] in_time 0 self.total_time += this_process_time self.total_time self total_time this_process_time self.makeLog(in_process[0]) self.makeLog self makeLog in_process[0] in_process 0 in_process.popleft() in_process.popleft in_process popleft in_time.popleft() in_time.popleft in_time popleft return in_process, in_time return in_process, in_time in_process in_time self self in_process in_process in_time in_time def makeLog(self, in_process):
        print(in_process, self.total_time)

     makeLog print(in_process, self.total_time) print in_process self.total_time self total_time self self in_process in_process processes = deque() processes deque() deque times = deque() times deque() deque data_cnt, quantum =  list(map(int,input().split(" "))) data_cnt list(map(int,input().split(" "))) list map(int,input().split(" ")) map int input().split(" ") ().split () input split " " quantum for i in range(data_cnt):
    tmp_process, tmp_time = input().split(" ")
    processes.append(tmp_process)
    times.append(int(tmp_time)) i range(data_cnt) range data_cnt tmp_process, tmp_time = input().split(" ") tmp_process input().split(" ") ().split () input split " " tmp_time processes.append(tmp_process) processes.append processes append tmp_process times.append(int(tmp_time)) times.append times append int(tmp_time) int tmp_time objCPU = CPU(quantum) objCPU CPU(quantum) CPU quantum while True:
    processes, times = objCPU.deal(processes, times)
    if len(processes) == 0:
        break True processes, times = objCPU.deal(processes, times) processes objCPU.deal(processes, times) objCPU.deal objCPU deal processes times times if len(processes) == 0:
        break len(processes) == 0 len(processes) len processes 0 break quantum =  list(map(int,input().split(" "))) list(map(int,input().split(" "))) quantum times = deque() deque() times tmp_time = input().split(" ") input().split(" ") tmp_time processes = deque() deque() processes data_cnt, quantum =  list(map(int,input().split(" "))) list(map(int,input().split(" "))) data_cnt class CPU():
    def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
    def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

    def makeLog(self, in_process):
        print(in_process, self.total_time)

     class CPU():
    def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
    def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

    def makeLog(self, in_process):
        print(in_process, self.total_time)

     CPU processes, times = objCPU.deal(processes, times) objCPU.deal(processes, times) processes times = objCPU.deal(processes, times) objCPU.deal(processes, times) times objCPU = CPU(quantum) CPU(quantum) objCPU tmp_process, tmp_time = input().split(" ") input().split(" ") tmp_process
# coding: utf-8
# Here your code !
import sys
from collections import deque

class CPU():
    def __init__(self, in_quantum):
        self.quantum = in_quantum
        self.total_time = 0
        
    def deal(self, in_process, in_time):
        this_process_time = 0

        if in_time[0] > self.quantum:
            remain_time = in_time[0] - self.quantum
            this_process_time = in_time[0] - remain_time

            in_process.append(in_process[0])
            in_time.append(remain_time)
            
            self.total_time += this_process_time
        else:
            this_process_time = in_time[0]
            self.total_time += this_process_time
            #make log
            self.makeLog(in_process[0])

        in_process.popleft()
        in_time.popleft()
        
        return in_process, in_time

    def makeLog(self, in_process):
        print(in_process, self.total_time)

    
processes = deque()
times = deque()
    
data_cnt, quantum =  list(map(int,input().split(" ")))  

for i in range(data_cnt):
    tmp_process, tmp_time = input().split(" ")
    processes.append(tmp_process)
    times.append(int(tmp_time))

objCPU = CPU(quantum)

while True:
    processes, times = objCPU.deal(processes, times)
    if len(processes) == 0:
        break