#coding:utf-8

#1_3_B

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

total_time = 0

queue = [input().split() for i in range(n)]



while queue:

    ps = queue.pop(0)

    time = int(ps[1])



    if time <= q:

        total_time += time

        print((ps[0], total_time))

    else:

        total_time += q

        time -= q

        ps[1] = time

        queue.append(ps)
#coding:utf-8

#1_3_B

from collections import deque



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

q = deque()

total_time = 0

for i in range(n):

    name, time = input().split()

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



while q:

    ps_name, ps_time = q.popleft()

    if ps_time <= quantum:

        total_time += ps_time

        print((ps_name, total_time))

    else:

        total_time += quantum

        ps_time -= quantum

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

# coding:utf-8
# 1_3_B
from collections import deque

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

-n, q = list(map(int, input().split())) +from collections import deque + +n, quantum = list(map(int, input().split())) +q = deque() -queue = [input().split() for i in range(n)] -while queue: -    ps = queue.pop(0) -    time = int(ps[1]) -    if time <= q: -        total_time += time -        print((ps[0], total_time)) +for i in range(n): +    name, time = input().split() +    q.append([name, int(time)]) +while q: +    ps_name, ps_time = q.popleft() +    if ps_time <= quantum: +        total_time += ps_time +        print((ps_name, total_time)) -        total_time += q -        time -= q -        ps[1] = time -        queue.append(ps) +        total_time += quantum +        ps_time -= quantum +        q.append([ps_name, ps_time])