#!/usr/bin/env python3

import sys


def main():
    lines = sys.stdin.readlines()
    (_, quantum) = lines[0].split(' ')
    quantum = int(quantum)

    processes = []
    for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

    time = 0
    result = []
    while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

    for item in result:
        print("%s %s" % (item[0], item[1]))

if __name__ == "__main__":
    main() import sys sys def main():
    lines = sys.stdin.readlines()
    (_, quantum) = lines[0].split(' ')
    quantum = int(quantum)

    processes = []
    for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

    time = 0
    result = []
    while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

    for item in result:
        print("%s %s" % (item[0], item[1])) main lines = sys.stdin.readlines() lines sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines (_, quantum) = lines[0].split(' ') (_, quantum) _ quantum lines[0].split(' ') [0].split [0] lines 0 split ' ' quantum = int(quantum) quantum int(quantum) int quantum processes = [] processes [] for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

     line lines[1:] lines 1: 1 if line.strip() == '':
            break

         line.strip() == '' line.strip() line.strip line strip '' break (k, v) = line.strip().split(' ') (k, v) k v line.strip().split(' ') line.strip().split line.strip() line.strip line strip split ' ' processes.append((k, int(v))) processes.append processes append (k, int(v)) k int(v) int v time = 0 time 0 result = [] result [] while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

     True (process, process_time) = processes.pop(0) (process, process_time) process process_time processes.pop(0) processes.pop processes pop 0 if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

         process_time <= quantum process_time quantum time += process_time time process_time result.append((process, time)) result.append result append (process, time) process time time += quantum time quantum processes.append((process, process_time - quantum)) processes.append processes append (process, process_time - quantum) process process_time - quantum process_time quantum if len(processes) == 0:
            break

     len(processes) == 0 len(processes) len processes 0 break for item in result:
        print("%s %s" % (item[0], item[1])) item result print("%s %s" % (item[0], item[1])) print "%s %s" % (item[0], item[1]) "%s %s" (item[0], item[1]) item[0] item 0 item[1] item 1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    lines = sys.stdin.readlines()
    (_, quantum) = lines[0].split(' ')
    quantum = int(quantum)

    processes = []
    for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

    time = 0
    result = []
    while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

    for item in result:
        print("%s %s" % (item[0], item[1])) def main():
    lines = sys.stdin.readlines()
    (_, quantum) = lines[0].split(' ')
    quantum = int(quantum)

    processes = []
    for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

    time = 0
    result = []
    while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

    for item in result:
        print("%s %s" % (item[0], item[1])) main
#!/usr/bin/env python3

import sys


def main():
    lines = sys.stdin.readlines()
    (_, quantum) = lines[0].split(' ')
    quantum = int(quantum)

    processes = []
    for line in lines[1:]:
        if line.strip() == '':
            break

        (k, v) = line.strip().split(' ')
        processes.append((k, int(v)))

    time = 0
    result = []
    while True:
        (process, process_time) = processes.pop(0)  # Dequeue

        if process_time <= quantum:
            time += process_time
            result.append((process, time))
        else:
            time += quantum
            processes.append((process, process_time - quantum))

        if len(processes) == 0:
            break

    for item in result:
        print("%s %s" % (item[0], item[1]))

if __name__ == "__main__":
    main()