#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
#?????\???
#??????????????¨????§?????????¨?????¨?????????????????????????????????????????????????????????
def rrs(quantum, process):
    finished_process = []
    queue = Queue()
    current_time = 0
    i = 0
    while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    return finished_process


class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
    
def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
    
if __name__ == "__main__":
    main() def rrs(quantum, process):
    finished_process = []
    queue = Queue()
    current_time = 0
    i = 0
    while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    return finished_process rrs finished_process = [] finished_process [] queue = Queue() queue Queue() Queue current_time = 0 current_time 0 i = 0 i 0 while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
     len(finished_process) < len(process) len(finished_process) len finished_process len(process) len process if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
         i < len(process) i len(process) len process p_info = process[i] p_info process[i] process i i += 1 i 1 p_info = queue.dequeue() p_info queue.dequeue() queue.dequeue queue dequeue time = int(p_info[1]) time int(p_info[1]) int p_info[1] p_info 1 name = p_info[0] name p_info[0] p_info 0 if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
     time <= quantum time quantum current_time += time current_time time finished_process.append((name, current_time)) finished_process.append finished_process append (name, current_time) name current_time current_time += quantum current_time quantum queue.enqueue((name, time - quantum)) queue.enqueue queue enqueue (name, time - quantum) name time - quantum time quantum return finished_process finished_process quantum quantum process process class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
     Queue def __init__(self):
        self.data = []

     __init__ self.data = [] self.data self data [] self self def enqueue(self, d):
        self.data.append(d)

     enqueue self.data.append(d) self.data.append self.data self data append d self self d d def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
     dequeue r = self.data[0] r self.data[0] self.data self data 0 self.data = self.data[1:] self.data self data self.data[1:] self.data self data 1: 1 return r r self self def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
     main info = input().split() info input().split() ().split () input split n_list = int(info[0]) n_list int(info[0]) int info[0] info 0 quantum = int(info[1]) quantum int(info[1]) int info[1] info 1 tuple(input().split()) for i in range(n_list) for i in range(n_list) i range(n_list) range n_list for i in range(n_list) tuple(input().split()) tuple input().split() ().split () input split target_list = [tuple(input().split()) for i in range(n_list)] target_list [tuple(input().split()) for i in range(n_list)] p + " " + str(t) for p,t in rrs(quantum, target_list) for p,t in rrs(quantum, target_list) p t rrs(quantum, target_list) rrs quantum target_list for p,t in rrs(quantum, target_list) p + " " + str(t) p + " " p " " str(t) str t print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)])) print "\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]) "\n".join "\n" join [p + " " + str(t) for p,t in rrs(quantum, target_list)] if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def rrs(quantum, process):
    finished_process = []
    queue = Queue()
    current_time = 0
    i = 0
    while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    return finished_process def rrs(quantum, process):
    finished_process = []
    queue = Queue()
    current_time = 0
    i = 0
    while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    return finished_process rrs def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
     def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
     main class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
     class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
     Queue
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B&lang=jp
#?????\???
#??????????????¨????§?????????¨?????¨?????????????????????????????????????????????????????????
def rrs(quantum, process):
    finished_process = []
    queue = Queue()
    current_time = 0
    i = 0
    while len(finished_process) < len(process):
        if i < len(process):
            p_info = process[i]
            i += 1
        else:
            p_info = queue.dequeue()
        time = int(p_info[1])
        name = p_info[0]
        
        if time <= quantum:
            current_time += time
            finished_process.append((name, current_time))
        else:
            current_time += quantum
            queue.enqueue((name, time - quantum))
            
    return finished_process


class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, d):
        self.data.append(d)

    def dequeue(self):
        r = self.data[0]
        self.data = self.data[1:]
        return r
    
def main():
    info = input().split()
    n_list = int(info[0])
    quantum = int(info[1])
    target_list = [tuple(input().split()) for i in range(n_list)]
    print("\n".join([p + " " + str(t) for p,t in rrs(quantum, target_list)]))
    
if __name__ == "__main__":
    main()