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

ps = [0]*n

t = [0]*n

for i in range( n ):

	ps[i], t[i] = input( ).split( " " )





output = []

qsum = 0

while t:

	psi = ps.pop( 0 )

	ti = int( t.pop( 0 ) )

	if ti <= q:

		qsum += ti	

		output.append( psi+" "+str( qsum ) )

	else:

		t.append( ti - q )

		ps.append( psi )

		qsum += q



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

ps = [0]*n

t = [0]*n

for i in range( n ):

    ps[i], t[i] = input( ).split( " " )

 

 

output = []

qsum = 0

while t:

    psi = ps.pop( 0 )

    ti = int( t.pop( 0 ) )

    if ti <= q:

        qsum += ti

        output.append( "".join( ( psi, " ", str( qsum ) ) ) )

    else:

        t.append( ti - q )

        ps.append( psi )

        qsum += q

 

print(( "\n".join( output ) ))
n, q = [int(val) for val in input().split(" ")]
ps = [0] * n
t = [0] * n
for i in range(n):
    ps[i], t[i] = input().split(" ")
output = []
qsum = 0
while t:
    psi = ps.pop(0)
    ti = int(t.pop(0))
    if ti <= q:
        qsum += ti
        output.append(psi + " " + str(qsum))
    else:
        t.append(ti - q)
        ps.append(psi)
        qsum += q
print(("\n".join(output)))

n, q = [int(val) for val in input().split(" ")]
ps = [0] * n
t = [0] * n
for i in range(n):
    ps[i], t[i] = input().split(" ")
output = []
qsum = 0
while t:
    psi = ps.pop(0)
    ti = int(t.pop(0))
    if ti <= q:
        qsum += ti
        output.append("".join((psi, " ", str(qsum))))
    else:
        t.append(ti - q)
        ps.append(psi)
        qsum += q
print(("\n".join(output)))

-        output.append(psi + " " + str(qsum)) +        output.append("".join((psi, " ", str(qsum))))