from queue import Queue



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

names = Queue( )

times = Queue( )

for i in range( n ):

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

	names.put( name )

	times.put( int( time ) )

 

qsum = 0

output = []

while not times.empty( ):

	name = names.get( )

	time = times.get( )

	if time <= q:

		qsum += time

		output.append( "{:s} {:d}".format( name, qsum ) )

	else:

		times.put( time - q )

		names.put( name )

		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 queue import Queue

n, q = [int(val) for val in input().split(" ")]
names = Queue()
times = Queue()
for i in range(n):
    name, time = input().split(" ")
    names.put(name)
    times.put(int(time))
qsum = 0
output = []
while not times.empty():
    name = names.get()
    time = times.get()
    if time <= q:
        qsum += time
        output.append("{:s} {:d}".format(name, qsum))
    else:
        times.put(time - q)
        names.put(name)
        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)))

-names = Queue() -times = Queue() +processes = Queue() -    names.put(name) -    times.put(int(time)) +    processes.put((name, int(time))) -while not times.empty(): -    name = names.get() -    time = times.get() -    if time <= q: -        qsum += time -        output.append("{:s} {:d}".format(name, qsum)) +while not processes.empty(): +    process = processes.get() +    if process[1] <= q: +        qsum += process[1] +        output.append("{:s} {:d}".format(process[0], qsum)) -        times.put(time - q) -        names.put(name) +        processes.put((process[0], process[1] - q))