def do_round_robin(process, tq):
    from collections import deque
    q = deque()
    elapsed_time = 0  # ??????????????????????§??????????????????????
    finished_process = []  # ????????????????????????????????????????????¨??????????????????????????§?????????

    # ?????\?????????????????????????????????
    for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

    while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
    return finished_process


if __name__ == '__main__':
    # ??????????????\???
    # ????????????????????????????????????????????????????°??????????????????????????????¨
    data = [int(x) for x in input().split(' ')]
    num_of_process = data[0]
    time_quantum = data[1]
    process = []
    for i in range(num_of_process):
        process.insert(0, [x for x in input().split(' ')])

    # ??????
    results = do_round_robin(process, time_quantum)

    # ???????????????
    for i in results:
        print('{0} {1}'.format(i[0], i[1])) def do_round_robin(process, tq):
    from collections import deque
    q = deque()
    elapsed_time = 0  # ??????????????????????§??????????????????????
    finished_process = []  # ????????????????????????????????????????????¨??????????????????????????§?????????

    # ?????\?????????????????????????????????
    for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

    while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
    return finished_process do_round_robin from collections import deque q = deque() q deque() deque elapsed_time = 0 elapsed_time 0 finished_process = [] finished_process [] for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

     process_name remaining_time process q.append([process_name, int(remaining_time)]) q.append q append [process_name, int(remaining_time)] process_name int(remaining_time) int remaining_time while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
     True try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
     except IndexError:  # ??????????????£???????????????????????????????????£???
            break
         break process_name, remaining_time = q.pop() process_name q.pop() q.pop q pop remaining_time elapsed_time += min(remaining_time, tq) elapsed_time min(remaining_time, tq) min remaining_time tq remaining_time -= tq remaining_time tq if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
     remaining_time > 0 remaining_time 0 q.appendleft([process_name, remaining_time]) q.appendleft q appendleft [process_name, remaining_time] process_name remaining_time finished_process.append((process_name, elapsed_time)) finished_process.append finished_process append (process_name, elapsed_time) process_name elapsed_time return finished_process finished_process process process tq tq if __name__ == '__main__':
    # ??????????????\???
    # ????????????????????????????????????????????????????°??????????????????????????????¨
    data = [int(x) for x in input().split(' ')]
    num_of_process = data[0]
    time_quantum = data[1]
    process = []
    for i in range(num_of_process):
        process.insert(0, [x for x in input().split(' ')])

    # ??????
    results = do_round_robin(process, time_quantum)

    # ???????????????
    for i in results:
        print('{0} {1}'.format(i[0], i[1])) __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 data = [int(x) for x in input().split(' ')] data [int(x) for x in input().split(' ')] num_of_process = data[0] num_of_process data[0] data 0 time_quantum = data[1] time_quantum data[1] data 1 process = [] process [] for i in range(num_of_process):
        process.insert(0, [x for x in input().split(' ')])

    # ??????
     i range(num_of_process) range num_of_process x for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') x process.insert(0, [x for x in input().split(' ')]) process.insert process insert 0 [x for x in input().split(' ')] results = do_round_robin(process, time_quantum) results do_round_robin(process, time_quantum) do_round_robin process time_quantum for i in results:
        print('{0} {1}'.format(i[0], i[1])) i results print('{0} {1}'.format(i[0], i[1])) print '{0} {1}'.format(i[0], i[1]) '{0} {1}'.format '{0} {1}' format i[0] i 0 i[1] i 1 process = [] [] process def do_round_robin(process, tq):
    from collections import deque
    q = deque()
    elapsed_time = 0  # ??????????????????????§??????????????????????
    finished_process = []  # ????????????????????????????????????????????¨??????????????????????????§?????????

    # ?????\?????????????????????????????????
    for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

    while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
    return finished_process def do_round_robin(process, tq):
    from collections import deque
    q = deque()
    elapsed_time = 0  # ??????????????????????§??????????????????????
    finished_process = []  # ????????????????????????????????????????????¨??????????????????????????§?????????

    # ?????\?????????????????????????????????
    for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

    while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
    return finished_process do_round_robin results = do_round_robin(process, time_quantum) do_round_robin(process, time_quantum) results time_quantum = data[1] data[1] time_quantum data = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] data num_of_process = data[0] data[0] num_of_process
def do_round_robin(process, tq):
    from collections import deque
    q = deque()
    elapsed_time = 0  # ??????????????????????§??????????????????????
    finished_process = []  # ????????????????????????????????????????????¨??????????????????????????§?????????

    # ?????\?????????????????????????????????
    for process_name, remaining_time in process:
        q.append([process_name, int(remaining_time)])

    while True:
        try:
            process_name, remaining_time = q.pop()
        except IndexError:  # ??????????????£???????????????????????????????????£???
            break
        else:
            elapsed_time += min(remaining_time, tq)
            remaining_time -= tq
            if remaining_time > 0:
                q.appendleft([process_name, remaining_time])
            else:
                finished_process.append((process_name, elapsed_time))
    return finished_process


if __name__ == '__main__':
    # ??????????????\???
    # ????????????????????????????????????????????????????°??????????????????????????????¨
    data = [int(x) for x in input().split(' ')]
    num_of_process = data[0]
    time_quantum = data[1]
    process = []
    for i in range(num_of_process):
        process.insert(0, [x for x in input().split(' ')])

    # ??????
    results = do_round_robin(process, time_quantum)

    # ???????????????
    for i in results:
        print('{0} {1}'.format(i[0], i[1]))