import queue

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

t = 0
while not queue.empty():
    name, time = queue.get()

    if time <= q:
        t += time
        print(name, t)
    else:
        queue.put((name, time - q))
        t += q
 import queue queue n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = queue.Queue() queue queue.Queue() queue.Queue queue Queue for i in range(n):
    name, time = input().split()
    queue.put((name, int(time))) i range(n) range n name, time = input().split() name input().split() ().split () input split time queue.put((name, int(time))) queue.put queue put (name, int(time)) name int(time) int time t = 0 t 0 while not queue.empty():
    name, time = queue.get()

    if time <= q:
        t += time
        print(name, t)
    else:
        queue.put((name, time - q))
        t += q not queue.empty() queue.empty() queue.empty queue empty name, time = queue.get() name queue.get() queue.get queue get time if time <= q:
        t += time
        print(name, t)
    else:
        queue.put((name, time - q))
        t += q time <= q time q t += time t time print(name, t) print name t queue.put((name, time - q)) queue.put queue put (name, time - q) name time - q time q t += q t q name, time = queue.get() queue.get() name t += q q t q = map(int, input().split()) map(int, input().split()) q t = 0 0 t time = queue.get() queue.get() time name, time = input().split() input().split() name n, q = map(int, input().split()) map(int, input().split()) n time = input().split() input().split() time t += time time t queue = queue.Queue() queue.Queue() queue
import queue

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

t = 0
while not queue.empty():
    name, time = queue.get()

    if time <= q:
        t += time
        print(name, t)
    else:
        queue.put((name, time - q))
        t += q

