class Process:
    def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

    def get_name(self):
        return self.name

    def get_time(self):
        return self.time

    def get_remaining_time(self):
        return self.remaing_time

    def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

    def get_complete_flg(self):
        return self.complete_flg

if __name__ == '__main__':
    n, q = [int(x) for x in input().split()]
    all_time = 0
    procesies = []
    for _ in range(n):
        name, time = input().split()
        temp_process = Process(name, int(time))
        procesies.append(temp_process)

    while len(procesies) != 0:
        target_process = procesies.pop(0)
        all_time += target_process.exec_process(q)
        if target_process.get_complete_flg():
            print(target_process.get_name() + " " + str(all_time))
        else:
            procesies.append(target_process)
 class Process:
    def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

    def get_name(self):
        return self.name

    def get_time(self):
        return self.time

    def get_remaining_time(self):
        return self.remaing_time

    def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

    def get_complete_flg(self):
        return self.complete_flg Process def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

     __init__ self.name = process_name self.name self name process_name self.time = process_time self.time self time process_time self.remaing_time = process_time self.remaing_time self remaing_time process_time self.complete_flg = False self.complete_flg self complete_flg False self self process_name process_name process_time process_time def get_name(self):
        return self.name

     get_name return self.name self.name self name self self def get_time(self):
        return self.time

     get_time return self.time self.time self time self self def get_remaining_time(self):
        return self.remaing_time

     get_remaining_time return self.remaing_time self.remaing_time self remaing_time self self def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

     exec_process if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

     self.remaing_time <= quantum self.remaing_time self remaing_time quantum self.complete_flg = True self.complete_flg self complete_flg True use_time = self.remaing_time use_time self.remaing_time self remaing_time self.remaing_time = 0 self.remaing_time self remaing_time 0 return use_time use_time self.remaing_time -= quantum self.remaing_time self remaing_time quantum return quantum quantum self self quantum quantum def get_complete_flg(self):
        return self.complete_flg get_complete_flg return self.complete_flg self.complete_flg self complete_flg self self if __name__ == '__main__':
    n, q = [int(x) for x in input().split()]
    all_time = 0
    procesies = []
    for _ in range(n):
        name, time = input().split()
        temp_process = Process(name, int(time))
        procesies.append(temp_process)

    while len(procesies) != 0:
        target_process = procesies.pop(0)
        all_time += target_process.exec_process(q)
        if target_process.get_complete_flg():
            print(target_process.get_name() + " " + str(all_time))
        else:
            procesies.append(target_process) __name__ == '__main__' __name__ '__main__' int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, q = [int(x) for x in input().split()] n [int(x) for x in input().split()] q all_time = 0 all_time 0 procesies = [] procesies [] for _ in range(n):
        name, time = input().split()
        temp_process = Process(name, int(time))
        procesies.append(temp_process)

     _ range(n) range n name, time = input().split() name input().split() ().split () input split time temp_process = Process(name, int(time)) temp_process Process(name, int(time)) Process name int(time) int time procesies.append(temp_process) procesies.append procesies append temp_process while len(procesies) != 0:
        target_process = procesies.pop(0)
        all_time += target_process.exec_process(q)
        if target_process.get_complete_flg():
            print(target_process.get_name() + " " + str(all_time))
        else:
            procesies.append(target_process) len(procesies) != 0 len(procesies) len procesies 0 target_process = procesies.pop(0) target_process procesies.pop(0) procesies.pop procesies pop 0 all_time += target_process.exec_process(q) all_time target_process.exec_process(q) target_process.exec_process target_process exec_process q if target_process.get_complete_flg():
            print(target_process.get_name() + " " + str(all_time))
        else:
            procesies.append(target_process) target_process.get_complete_flg() target_process.get_complete_flg target_process get_complete_flg print(target_process.get_name() + " " + str(all_time)) print target_process.get_name() + " " + str(all_time) target_process.get_name() + " " target_process.get_name() target_process.get_name target_process get_name " " str(all_time) str all_time procesies.append(target_process) procesies.append procesies append target_process n, q = [int(x) for x in input().split()] [int(x) for x in input().split()] n name, time = input().split() input().split() name all_time = 0 0 all_time target_process = procesies.pop(0) procesies.pop(0) target_process q = [int(x) for x in input().split()] [int(x) for x in input().split()] q all_time += target_process.exec_process(q) target_process.exec_process(q) all_time procesies = [] [] procesies temp_process = Process(name, int(time)) Process(name, int(time)) temp_process class Process:
    def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

    def get_name(self):
        return self.name

    def get_time(self):
        return self.time

    def get_remaining_time(self):
        return self.remaing_time

    def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

    def get_complete_flg(self):
        return self.complete_flg class Process:
    def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

    def get_name(self):
        return self.name

    def get_time(self):
        return self.time

    def get_remaining_time(self):
        return self.remaing_time

    def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

    def get_complete_flg(self):
        return self.complete_flg Process time = input().split() input().split() time
class Process:
    def __init__(self, process_name, process_time):
        self.name = process_name
        self.time = process_time
        self.remaing_time = process_time
        self.complete_flg = False

    def get_name(self):
        return self.name

    def get_time(self):
        return self.time

    def get_remaining_time(self):
        return self.remaing_time

    def exec_process(self, quantum):
        if self.remaing_time <= quantum:
            self.complete_flg = True
            use_time = self.remaing_time
            self.remaing_time = 0
            return use_time
        else:
            self.remaing_time -= quantum
            return quantum

    def get_complete_flg(self):
        return self.complete_flg

if __name__ == '__main__':
    n, q = [int(x) for x in input().split()]
    all_time = 0
    procesies = []
    for _ in range(n):
        name, time = input().split()
        temp_process = Process(name, int(time))
        procesies.append(temp_process)

    while len(procesies) != 0:
        target_process = procesies.pop(0)
        all_time += target_process.exec_process(q)
        if target_process.get_complete_flg():
            print(target_process.get_name() + " " + str(all_time))
        else:
            procesies.append(target_process)

