from collections import deque

n, q = map(int, input().split())
queue = deque([])
for i in range(n):
    a = input().split()
    queue.append([a[0], int(a[1])])

time = 0

while queue:
    b = queue.popleft()
    if b[1] <= q:
        time += b[1]
        print(b[0] + ' ' + str(time))
    else:
        b[1] -= q
        time += q
        queue.append(b) from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = deque([]) queue deque([]) deque [] for i in range(n):
    a = input().split()
    queue.append([a[0], int(a[1])]) i range(n) range n a = input().split() a input().split() ().split () input split queue.append([a[0], int(a[1])]) queue.append queue append [a[0], int(a[1])] a[0] a 0 int(a[1]) int a[1] a 1 time = 0 time 0 while queue:
    b = queue.popleft()
    if b[1] <= q:
        time += b[1]
        print(b[0] + ' ' + str(time))
    else:
        b[1] -= q
        time += q
        queue.append(b) queue b = queue.popleft() b queue.popleft() queue.popleft queue popleft if b[1] <= q:
        time += b[1]
        print(b[0] + ' ' + str(time))
    else:
        b[1] -= q
        time += q
        queue.append(b) b[1] <= q b[1] b 1 q time += b[1] time b[1] b 1 print(b[0] + ' ' + str(time)) print b[0] + ' ' + str(time) b[0] + ' ' b[0] b 0 ' ' str(time) str time b[1] -= q b[1] b 1 q time += q time q queue.append(b) queue.append queue append b time += q q time q = map(int, input().split()) map(int, input().split()) q time += b[1] b[1] time a = input().split() input().split() a b = queue.popleft() queue.popleft() b n, q = map(int, input().split()) map(int, input().split()) n queue = deque([]) deque([]) queue time = 0 0 time
from collections import deque

n, q = map(int, input().split())
queue = deque([])
for i in range(n):
    a = input().split()
    queue.append([a[0], int(a[1])])

time = 0

while queue:
    b = queue.popleft()
    if b[1] <= q:
        time += b[1]
        print(b[0] + ' ' + str(time))
    else:
        b[1] -= q
        time += q
        queue.append(b)