import queue
procs = queue.Queue()

n,q = list(map(int,input().split()))

for i in range(n):
    name,time = input().split()
    procs.put((name,int(time)))
time=0
doneprocs = queue.Queue()
while True:
    if procs.empty():
        break
    temp = procs.get()
    if temp[1] <= q:
        time += temp[1]
        doneprocs.put((temp[0],time))
    else:
        time+= q
        procs.put((temp[0],temp[1]-q))
for i in range(n):
    temp = doneprocs.get()
    print(temp[0],temp[1]) import queue queue procs = queue.Queue() procs queue.Queue() queue.Queue queue Queue n,q = list(map(int,input().split())) n list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split q for i in range(n):
    name,time = input().split()
    procs.put((name,int(time))) i range(n) range n name,time = input().split() name input().split() ().split () input split time procs.put((name,int(time))) procs.put procs put (name,int(time)) name int(time) int time time=0 time 0 doneprocs = queue.Queue() doneprocs queue.Queue() queue.Queue queue Queue while True:
    if procs.empty():
        break
    temp = procs.get()
    if temp[1] <= q:
        time += temp[1]
        doneprocs.put((temp[0],time))
    else:
        time+= q
        procs.put((temp[0],temp[1]-q)) True if procs.empty():
        break
     procs.empty() procs.empty procs empty break temp = procs.get() temp procs.get() procs.get procs get if temp[1] <= q:
        time += temp[1]
        doneprocs.put((temp[0],time))
    else:
        time+= q
        procs.put((temp[0],temp[1]-q)) temp[1] <= q temp[1] temp 1 q time += temp[1] time temp[1] temp 1 doneprocs.put((temp[0],time)) doneprocs.put doneprocs put (temp[0],time) temp[0] temp 0 time time+= q time q procs.put((temp[0],temp[1]-q)) procs.put procs put (temp[0],temp[1]-q) temp[0] temp 0 temp[1]-q temp[1] temp 1 q for i in range(n):
    temp = doneprocs.get()
    print(temp[0],temp[1]) i range(n) range n temp = doneprocs.get() temp doneprocs.get() doneprocs.get doneprocs get print(temp[0],temp[1]) print temp[0] temp 0 temp[1] temp 1 n,q = list(map(int,input().split())) list(map(int,input().split())) n time+= q q time temp = doneprocs.get() doneprocs.get() temp time=0 0 time temp = procs.get() procs.get() temp procs = queue.Queue() queue.Queue() procs time = input().split() input().split() time time += temp[1] temp[1] time q = list(map(int,input().split())) list(map(int,input().split())) q doneprocs = queue.Queue() queue.Queue() doneprocs name,time = input().split() input().split() name
import queue
procs = queue.Queue()

n,q = list(map(int,input().split()))

for i in range(n):
    name,time = input().split()
    procs.put((name,int(time)))
time=0
doneprocs = queue.Queue()
while True:
    if procs.empty():
        break
    temp = procs.get()
    if temp[1] <= q:
        time += temp[1]
        doneprocs.put((temp[0],time))
    else:
        time+= q
        procs.put((temp[0],temp[1]-q))
for i in range(n):
    temp = doneprocs.get()
    print(temp[0],temp[1])