from queue import Queue

 

n, q = [ int( val ) for val in input( ).split( " " ) ]

processes = Queue( )

for i in range( n ):

    name, time = input( ).split( " " )

    processes.put( ( name, int( time ) ) )

  

qsum = 0

output = []

while not processes.empty( ):

    process = processes.get( )

    if process[1] <= q:

        qsum += process[1]

        output.append( "{:s} {:d}".format( process[0], qsum ) )

    else:

        processes.put( ( process[0], process[1]- q ) )

        qsum += q

 

print(( "\n".join( output ) ))
from collections import deque



n, q = [ int( val ) for val in input( ).split( " " ) ]

processes = deque( )

for i in range( n ):

    name, time = input( ).split( " " )

    processes.append( ( name, int( time ) ) )

  

qsum = 0

output = []

while len( processes ):

    process = processes.popleft( )

    if process[1] <= q:

        qsum += process[1]

        output.append( "{:s} {:d}".format( process[0], qsum ) )

    else:

        processes.append( ( process[0], process[1]- q ) )

        qsum += q

 

print(( "\n".join( output ) ))
from queue import Queue

n, q = [int(val) for val in input().split(" ")]
processes = Queue()
for i in range(n):
    name, time = input().split(" ")
    processes.put((name, int(time)))
qsum = 0
output = []
while not processes.empty():
    process = processes.get()
    if process[1] <= q:
        qsum += process[1]
        output.append("{:s} {:d}".format(process[0], qsum))
    else:
        processes.put((process[0], process[1] - q))
        qsum += q
print(("\n".join(output)))

from collections import deque

n, q = [int(val) for val in input().split(" ")]
processes = deque()
for i in range(n):
    name, time = input().split(" ")
    processes.append((name, int(time)))
qsum = 0
output = []
while len(processes):
    process = processes.popleft()
    if process[1] <= q:
        qsum += process[1]
        output.append("{:s} {:d}".format(process[0], qsum))
    else:
        processes.append((process[0], process[1] - q))
        qsum += q
print(("\n".join(output)))

-from queue import Queue +from collections import deque -processes = Queue() +processes = deque() -    processes.put((name, int(time))) +    processes.append((name, int(time))) -while not processes.empty(): -    process = processes.get() +while len(processes): +    process = processes.popleft() -        processes.put((process[0], process[1] - q)) +        processes.append((process[0], process[1] - q))