def main():
    process, quantum = input().split()
    process = int(process)
    quantum = int(quantum)
    processes = []
    for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
    ptime = 0
    while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime))




if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() def main():
    process, quantum = input().split()
    process = int(process)
    quantum = int(quantum)
    processes = []
    for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
    ptime = 0
    while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime)) main process, quantum = input().split() process input().split() ().split () input split quantum process = int(process) process int(process) int process quantum = int(quantum) quantum int(quantum) int quantum processes = [] processes [] for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
     i range(process) range process t, u = input().split() t input().split() ().split () input split u processes.append((t, int(u))) processes.append processes append (t, int(u)) t int(u) int u ptime = 0 ptime 0 while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime)) len(processes) > 0 len(processes) len processes 0 t = processes.pop(0) t processes.pop(0) processes.pop processes pop 0 if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime)) t[1] > quantum t[1] t 1 quantum processes.append((t[0], t[1]-quantum)) processes.append processes append (t[0], t[1]-quantum) t[0] t 0 t[1]-quantum t[1] t 1 quantum ptime += quantum ptime quantum ptime += t[1] ptime t[1] t 1 print(t[0] + " " + str(ptime)) print t[0] + " " + str(ptime) t[0] + " " t[0] t 0 " " str(ptime) str ptime if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() __name__ == "__main__" __name__ "__main__" import os os import sys sys if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main() len(sys.argv) > 1 len(sys.argv) len sys.argv sys argv 1 if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
     sys.argv[1] == "-d" sys.argv[1] sys.argv sys argv 1 "-d" fd = os.open("input.txt", os.O_RDONLY) fd os.open("input.txt", os.O_RDONLY) os.open os open "input.txt" os.O_RDONLY os O_RDONLY os.dup2(fd, sys.stdin.fileno()) os.dup2 os dup2 fd sys.stdin.fileno() sys.stdin.fileno sys.stdin sys stdin fileno main() main main() main def main():
    process, quantum = input().split()
    process = int(process)
    quantum = int(quantum)
    processes = []
    for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
    ptime = 0
    while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime)) def main():
    process, quantum = input().split()
    process = int(process)
    quantum = int(quantum)
    processes = []
    for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
    ptime = 0
    while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime)) main fd = os.open("input.txt", os.O_RDONLY) os.open("input.txt", os.O_RDONLY) fd
def main():
    process, quantum = input().split()
    process = int(process)
    quantum = int(quantum)
    processes = []
    for i in range(process):
        t, u = input().split()
        processes.append((t, int(u)))
    ptime = 0
    while len(processes) > 0:
        t = processes.pop(0)
        if t[1] > quantum:
            processes.append((t[0], t[1]-quantum))
            ptime += quantum
        else:
            ptime += t[1]
            print(t[0] + " " + str(ptime))




if __name__ == "__main__":
    import os
    import sys
    if len(sys.argv) > 1:
        if sys.argv[1] == "-d":
            fd = os.open("input.txt", os.O_RDONLY)
            os.dup2(fd, sys.stdin.fileno())
            main()
    else:
        main()