from collections import deque

n, qt = map(int, input().split())

queue = deque()

for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

total_time = 0

while queue:
    q_t = queue.popleft()
    if q_t[1] <= qt:
        total_time += q_t[1]
        print(q_t[0], total_time)
    else:
        total_time += qt
        q_t[1] -= qt
        queue.append(q_t) from collections import deque n, qt = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split qt queue = deque() queue deque() deque for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)]) i range(n) range n name, time = input().split() name input().split() ().split () input split time queue.append([name, int(time)]) queue.append queue append [name, int(time)] name int(time) int time total_time = 0 total_time 0 while queue:
    q_t = queue.popleft()
    if q_t[1] <= qt:
        total_time += q_t[1]
        print(q_t[0], total_time)
    else:
        total_time += qt
        q_t[1] -= qt
        queue.append(q_t) queue q_t = queue.popleft() q_t queue.popleft() queue.popleft queue popleft if q_t[1] <= qt:
        total_time += q_t[1]
        print(q_t[0], total_time)
    else:
        total_time += qt
        q_t[1] -= qt
        queue.append(q_t) q_t[1] <= qt q_t[1] q_t 1 qt total_time += q_t[1] total_time q_t[1] q_t 1 print(q_t[0], total_time) print q_t[0] q_t 0 total_time total_time += qt total_time qt q_t[1] -= qt q_t[1] q_t 1 qt queue.append(q_t) queue.append queue append q_t qt = map(int, input().split()) map(int, input().split()) qt total_time = 0 0 total_time q_t = queue.popleft() queue.popleft() q_t n, qt = map(int, input().split()) map(int, input().split()) n name, time = input().split() input().split() name queue = deque() deque() queue total_time += qt qt total_time total_time += q_t[1] q_t[1] total_time time = input().split() input().split() time
from collections import deque

n, qt = map(int, input().split())

queue = deque()

for i in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

total_time = 0

while queue:
    q_t = queue.popleft()
    if q_t[1] <= qt:
        total_time += q_t[1]
        print(q_t[0], total_time)
    else:
        total_time += qt
        q_t[1] -= qt
        queue.append(q_t)