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

while not qe.empty():
    item = qe.get()
    if item is None:
        break
    name, time = item
    c = min(q, time)
    current += c
    time -= c
    if time > 0:
        qe.put((name, time))
    else:
        print(name + ' ' + str(current)) from queue import Queue n,q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q qe = Queue() qe Queue() Queue current = 0 current 0 for i in range(n):
    name, time = input().split()
    time = int(time)
    qe.put((name, time)) i range(n) range n name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time qe.put((name, time)) qe.put qe put (name, time) name time while not qe.empty():
    item = qe.get()
    if item is None:
        break
    name, time = item
    c = min(q, time)
    current += c
    time -= c
    if time > 0:
        qe.put((name, time))
    else:
        print(name + ' ' + str(current)) not qe.empty() qe.empty() qe.empty qe empty item = qe.get() item qe.get() qe.get qe get if item is None:
        break
     item is None item None break name, time = item name item time c = min(q, time) c min(q, time) min q time current += c current c time -= c time c if time > 0:
        qe.put((name, time))
    else:
        print(name + ' ' + str(current)) time > 0 time 0 qe.put((name, time)) qe.put qe put (name, time) name time print(name + ' ' + str(current)) print name + ' ' + str(current) name + ' ' name ' ' str(current) str current time = int(time) int(time) time n,q = map(int,input().split()) map(int,input().split()) n name, time = input().split() input().split() name time -= c c time q = map(int,input().split()) map(int,input().split()) q time = input().split() input().split() time time = item item time current = 0 0 current current += c c current name, time = item item name item = qe.get() qe.get() item c = min(q, time) min(q, time) c qe = Queue() Queue() qe
from queue import Queue
n,q = map(int,input().split())
qe = Queue()
current = 0
for i in range(n):
    name, time = input().split()
    time = int(time)
    qe.put((name, time))

while not qe.empty():
    item = qe.get()
    if item is None:
        break
    name, time = item
    c = min(q, time)
    current += c
    time -= c
    if time > 0:
        qe.put((name, time))
    else:
        print(name + ' ' + str(current))