# coding:utf-8
# Round-robin scheduling

def main():
    n, q = map(int, input().split())
    process = []
    finished = []
    counter = 0
    for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

    while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
    for name, time in finished:
        print(name, time)

if __name__ == "__main__":
    main() def main():
    n, q = map(int, input().split())
    process = []
    finished = []
    counter = 0
    for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

    while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
    for name, time in finished:
        print(name, time) main n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q process = [] process [] finished = [] finished [] counter = 0 counter 0 for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

     _ range(n) range n name, time = input().split() name input().split() ().split () input split time process.append((name, int(time))) process.append process append (name, int(time)) name int(time) int time while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
     len(process)  > 0 len(process) len process 0 name, time = process.pop(0) name process.pop(0) process.pop process pop 0 time temp_q = q temp_q q while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
     True if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
             time <= 0 time 0 finished.append((name, counter)) finished.append finished append (name, counter) name counter break if temp_q <= 0:
                process.append((name, time))
                break
            
             temp_q <= 0 temp_q 0 process.append((name, time)) process.append process append (name, time) name time break time -= 1 time 1 temp_q -= 1 temp_q 1 counter += 1 counter 1 for name, time in finished:
        print(name, time) name time finished print(name, time) print name time if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, q = map(int, input().split())
    process = []
    finished = []
    counter = 0
    for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

    while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
    for name, time in finished:
        print(name, time) def main():
    n, q = map(int, input().split())
    process = []
    finished = []
    counter = 0
    for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

    while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
    for name, time in finished:
        print(name, time) main
# coding:utf-8
# Round-robin scheduling

def main():
    n, q = map(int, input().split())
    process = []
    finished = []
    counter = 0
    for _ in range(n):
        name, time = input().split()
        process.append((name, int(time)))

    while len(process)  > 0:
        name, time = process.pop(0)
        temp_q = q

        while True:
            
            if time <= 0:
                finished.append((name, counter))
                break

            # q????????§??????????¶????????????£???????????????
            # time?????´??°??????process???????°?????§???? 
            if temp_q <= 0:
                process.append((name, time))
                break
            
            time -= 1
            temp_q -= 1
            counter += 1
    
    for name, time in finished:
        print(name, time)

if __name__ == "__main__":
    main()