# coding=utf-8



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

queue = []

total_time = 0

finished_loop = 0



for i in range(n):

    name, time = input().split()

    queue.append([name, int(time)])



while queue:

    n -= finished_loop

    finished_loop = 0

    for i in range(n):

        poped = queue.pop(0)

        name = poped[0]

        time = poped[1]

        if time > q:

            queue.append([name, time - q])

            total_time += q

        else:

            total_time += time

            print((name, total_time))

            finished_loop += 1
# coding=utf-8

from collections import deque



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

queue = deque()

total_time = 0



for i in range(n):

    name, time = input().split()

    queue.append([name, int(time)])



while queue:

    poped = queue.popleft()

    if poped[1] > q:

        queue.append([poped[0], poped[1] - q])

        total_time += q

    else:

        total_time += poped[1]

        print((poped[0], total_time))
# coding=utf-8
n, q = list(map(int, input().split()))
queue = []
total_time = 0
finished_loop = 0
for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])
while queue:
    n -= finished_loop
    finished_loop = 0
    for i in range(n):
        poped = queue.pop(0)
        name = poped[0]
        time = poped[1]
        if time > q:
            queue.append([name, time - q])
            total_time += q
        else:
            total_time += time
            print((name, total_time))
            finished_loop += 1

# coding=utf-8
from collections import deque

n, q = list(map(int, input().split()))
queue = deque()
total_time = 0
for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])
while queue:
    poped = queue.popleft()
    if poped[1] > q:
        queue.append([poped[0], poped[1] - q])
        total_time += q
    else:
        total_time += poped[1]
        print((poped[0], total_time))

+from collections import deque + -queue = [] +queue = deque() -finished_loop = 0 -    n -= finished_loop -    finished_loop = 0 -    for i in range(n): -        poped = queue.pop(0) -        name = poped[0] -        time = poped[1] -        if time > q: -            queue.append([name, time - q]) -            total_time += q -        else: -            total_time += time -            print((name, total_time)) -            finished_loop += 1 +    poped = queue.popleft() +    if poped[1] > q: +        queue.append([poped[0], poped[1] - q]) +        total_time += q +    else: +        total_time += poped[1] +        print((poped[0], total_time))