import queue

n, quantum = map(int, input().split())
q = queue.Queue()
for _ in range(n):
    name, time = input().split()
    q.put([name, int(time)])

spend_time = 0
while q.qsize() > 0:
    name, time = q.get()
    tmp = min(quantum, time)
    spend_time += tmp
    time -= tmp
    if time == 0:
        print('{} {}'.format(name, spend_time))
    else:
        q.put([name, time])
 import queue queue n, quantum = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split quantum q = queue.Queue() q queue.Queue() queue.Queue queue Queue for _ in range(n):
    name, time = input().split()
    q.put([name, int(time)]) _ range(n) range n name, time = input().split() name input().split() ().split () input split time q.put([name, int(time)]) q.put q put [name, int(time)] name int(time) int time spend_time = 0 spend_time 0 while q.qsize() > 0:
    name, time = q.get()
    tmp = min(quantum, time)
    spend_time += tmp
    time -= tmp
    if time == 0:
        print('{} {}'.format(name, spend_time))
    else:
        q.put([name, time]) q.qsize() > 0 q.qsize() q.qsize q qsize 0 name, time = q.get() name q.get() q.get q get time tmp = min(quantum, time) tmp min(quantum, time) min quantum time spend_time += tmp spend_time tmp time -= tmp time tmp if time == 0:
        print('{} {}'.format(name, spend_time))
    else:
        q.put([name, time]) time == 0 time 0 print('{} {}'.format(name, spend_time)) print '{} {}'.format(name, spend_time) '{} {}'.format '{} {}' format name spend_time q.put([name, time]) q.put q put [name, time] name time tmp = min(quantum, time) min(quantum, time) tmp n, quantum = map(int, input().split()) map(int, input().split()) n name, time = input().split() input().split() name time = input().split() input().split() time spend_time += tmp tmp spend_time q = queue.Queue() queue.Queue() q name, time = q.get() q.get() name spend_time = 0 0 spend_time time = q.get() q.get() time quantum = map(int, input().split()) map(int, input().split()) quantum time -= tmp tmp time
import queue

n, quantum = map(int, input().split())
q = queue.Queue()
for _ in range(n):
    name, time = input().split()
    q.put([name, int(time)])

spend_time = 0
while q.qsize() > 0:
    name, time = q.get()
    tmp = min(quantum, time)
    spend_time += tmp
    time -= tmp
    if time == 0:
        print('{} {}'.format(name, spend_time))
    else:
        q.put([name, time])

