queue,decrease = (int(n) for n in input().split(' '))
targ = []
for q in range(queue):
    targ.append([n for n in input().split(' ')])
length = 0
time = 0
while True:

    if int(targ[length][1]) - decrease <= 0:
        time += int(targ[length][1])
        print(str(targ[length][0]) + " " + str(time))
        targ.pop(length)
        queue -= 1
        if queue == 0:
            break
        length = (length) % queue
        
    else:
        time += decrease
        targ[length][1] = int(targ[length][1]) - decrease
        length = (length + 1) % queue int(n) for n in input().split(' ') for n in input().split(' ') n input().split(' ') ().split () input split ' ' for n in input().split(' ') int(n) int n queue,decrease = (int(n) for n in input().split(' ')) queue (int(n) for n in input().split(' ')) decrease targ = [] targ [] for q in range(queue):
    targ.append([n for n in input().split(' ')]) q range(queue) range queue n for n in input().split(' ') for n in input().split(' ') n input().split(' ') ().split () input split ' ' for n in input().split(' ') n targ.append([n for n in input().split(' ')]) targ.append targ append [n for n in input().split(' ')] length = 0 length 0 time = 0 time 0 while True:

    if int(targ[length][1]) - decrease <= 0:
        time += int(targ[length][1])
        print(str(targ[length][0]) + " " + str(time))
        targ.pop(length)
        queue -= 1
        if queue == 0:
            break
        length = (length) % queue
        
    else:
        time += decrease
        targ[length][1] = int(targ[length][1]) - decrease
        length = (length + 1) % queue True if int(targ[length][1]) - decrease <= 0:
        time += int(targ[length][1])
        print(str(targ[length][0]) + " " + str(time))
        targ.pop(length)
        queue -= 1
        if queue == 0:
            break
        length = (length) % queue
        
    else:
        time += decrease
        targ[length][1] = int(targ[length][1]) - decrease
        length = (length + 1) % queue int(targ[length][1]) - decrease <= 0 int(targ[length][1]) - decrease int(targ[length][1]) int targ[length][1] [length] targ length 1 decrease 0 time += int(targ[length][1]) time int(targ[length][1]) int targ[length][1] [length] targ length 1 print(str(targ[length][0]) + " " + str(time)) print str(targ[length][0]) + " " + str(time) str(targ[length][0]) + " " str(targ[length][0]) str targ[length][0] [length] targ length 0 " " str(time) str time targ.pop(length) targ.pop targ pop length queue -= 1 queue 1 if queue == 0:
            break
         queue == 0 queue 0 break length = (length) % queue length (length) % queue length queue time += decrease time decrease targ[length][1] = int(targ[length][1]) - decrease targ[length][1] [length] targ length 1 int(targ[length][1]) - decrease int(targ[length][1]) int targ[length][1] [length] targ length 1 decrease length = (length + 1) % queue length (length + 1) % queue length + 1 length 1 queue targ = [] [] targ time += decrease decrease time decrease = (int(n) for n in input().split(' ')) (int(n) for n in input().split(' ')) decrease length = 0 0 length queue -= 1 1 queue time = 0 0 time time += int(targ[length][1]) int(targ[length][1]) time queue,decrease = (int(n) for n in input().split(' ')) (int(n) for n in input().split(' ')) queue length = (length + 1) % queue (length + 1) % queue length length = (length) % queue (length) % queue length
queue,decrease = (int(n) for n in input().split(' '))
targ = []
for q in range(queue):
    targ.append([n for n in input().split(' ')])
length = 0
time = 0
while True:

    if int(targ[length][1]) - decrease <= 0:
        time += int(targ[length][1])
        print(str(targ[length][0]) + " " + str(time))
        targ.pop(length)
        queue -= 1
        if queue == 0:
            break
        length = (length) % queue
        
    else:
        time += decrease
        targ[length][1] = int(targ[length][1]) - decrease
        length = (length + 1) % queue