# coding: utf-8

import sys
from collections import deque

n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))

for task in tasks:
    task[1] = int(task[1])

try:
    while True:
        t = tasks.popleft()
        if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t)
except Exception:
    pass import sys sys from collections import deque n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q total_time = 0 total_time 0 tasks = deque(map(lambda x: x.split(), sys.stdin.readlines())) tasks deque(map(lambda x: x.split(), sys.stdin.readlines())) deque map(lambda x: x.split(), sys.stdin.readlines()) map lambda x: x.split() x.split() x.split x split x sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines for task in tasks:
    task[1] = int(task[1]) task tasks task[1] = int(task[1]) task[1] task 1 int(task[1]) int task[1] task 1 try:
    while True:
        t = tasks.popleft()
        if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t)
except Exception:
    pass except Exception:
    pass while True:
        t = tasks.popleft()
        if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t) True t = tasks.popleft() t tasks.popleft() tasks.popleft tasks popleft if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t) t[1] - q <= 0 t[1] - q t[1] t 1 q 0 total_time += t[1] total_time t[1] t 1 print(t[0], total_time) print t[0] t 0 total_time t[1] = t[1] - q t[1] t 1 t[1] - q t[1] t 1 q total_time += q total_time q tasks.append(t) tasks.append tasks append t n, q = map(int, input().split()) map(int, input().split()) n total_time += t[1] t[1] total_time q = map(int, input().split()) map(int, input().split()) q total_time = 0 0 total_time total_time += q q total_time t = tasks.popleft() tasks.popleft() t tasks = deque(map(lambda x: x.split(), sys.stdin.readlines())) deque(map(lambda x: x.split(), sys.stdin.readlines())) tasks
# coding: utf-8

import sys
from collections import deque

n, q = map(int, input().split())
total_time = 0
tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))

for task in tasks:
    task[1] = int(task[1])

try:
    while True:
        t = tasks.popleft()
        if t[1] - q <= 0:
            total_time += t[1]
            print(t[0], total_time)
        else:
            t[1] = t[1] - q
            total_time += q
            tasks.append(t)
except Exception:
    pass