#! python3
# queue.py

from collections import deque

n, q = [int(x) for x in input().split(' ')]

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

elapsed_time = 0
while True:
    proc = queue.popleft()
    if proc[1] - q <= 0:
        elapsed_time += proc[1]
        print(proc[0], elapsed_time)
    else:
        elapsed_time += q
        queue.append([proc[0], proc[1] - q])
    if len(queue) == 0:
        break from collections import deque int(x) for x in input().split(' ') for x in input().split(' ') x input().split(' ') ().split () input split ' ' for x in input().split(' ') int(x) int x n, q = [int(x) for x in input().split(' ')] n [int(x) for x in input().split(' ')] q queue = deque([]) queue deque([]) deque [] for i in range(n):
    inp = input().split(' ')
    queue.append([inp[0], int(inp[1])]) i range(n) range n inp = input().split(' ') inp input().split(' ') ().split () input split ' ' queue.append([inp[0], int(inp[1])]) queue.append queue append [inp[0], int(inp[1])] inp[0] inp 0 int(inp[1]) int inp[1] inp 1 elapsed_time = 0 elapsed_time 0 while True:
    proc = queue.popleft()
    if proc[1] - q <= 0:
        elapsed_time += proc[1]
        print(proc[0], elapsed_time)
    else:
        elapsed_time += q
        queue.append([proc[0], proc[1] - q])
    if len(queue) == 0:
        break True proc = queue.popleft() proc queue.popleft() queue.popleft queue popleft if proc[1] - q <= 0:
        elapsed_time += proc[1]
        print(proc[0], elapsed_time)
    else:
        elapsed_time += q
        queue.append([proc[0], proc[1] - q])
     proc[1] - q <= 0 proc[1] - q proc[1] proc 1 q 0 elapsed_time += proc[1] elapsed_time proc[1] proc 1 print(proc[0], elapsed_time) print proc[0] proc 0 elapsed_time elapsed_time += q elapsed_time q queue.append([proc[0], proc[1] - q]) queue.append queue append [proc[0], proc[1] - q] proc[0] proc 0 proc[1] - q proc[1] proc 1 q if len(queue) == 0:
        break len(queue) == 0 len(queue) len queue 0 break n, q = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] n proc = queue.popleft() queue.popleft() proc elapsed_time += proc[1] proc[1] elapsed_time inp = input().split(' ') input().split(' ') inp q = [int(x) for x in input().split(' ')] [int(x) for x in input().split(' ')] q queue = deque([]) deque([]) queue elapsed_time = 0 0 elapsed_time elapsed_time += q q elapsed_time
#! python3
# queue.py

from collections import deque

n, q = [int(x) for x in input().split(' ')]

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

elapsed_time = 0
while True:
    proc = queue.popleft()
    if proc[1] - q <= 0:
        elapsed_time += proc[1]
        print(proc[0], elapsed_time)
    else:
        elapsed_time += q
        queue.append([proc[0], proc[1] - q])
    if len(queue) == 0:
        break
