# 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()))

try:
    while True:
        t = tasks.popleft()
        if int(t[1]) - q <= 0:
            total_time += int(t[1])
            print(t[0], total_time)
        else:
            t[1] = str(int(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 try:
    while True:
        t = tasks.popleft()
        if int(t[1]) - q <= 0:
            total_time += int(t[1])
            print(t[0], total_time)
        else:
            t[1] = str(int(t[1]) - q)
            total_time += q
            tasks.append(t)
except Exception:
    pass except Exception:
    pass while True:
        t = tasks.popleft()
        if int(t[1]) - q <= 0:
            total_time += int(t[1])
            print(t[0], total_time)
        else:
            t[1] = str(int(t[1]) - q)
            total_time += q
            tasks.append(t) True t = tasks.popleft() t tasks.popleft() tasks.popleft tasks popleft if int(t[1]) - q <= 0:
            total_time += int(t[1])
            print(t[0], total_time)
        else:
            t[1] = str(int(t[1]) - q)
            total_time += q
            tasks.append(t) int(t[1]) - q <= 0 int(t[1]) - q int(t[1]) int t[1] t 1 q 0 total_time += int(t[1]) total_time int(t[1]) int t[1] t 1 print(t[0], total_time) print t[0] t 0 total_time t[1] = str(int(t[1]) - q) t[1] t 1 str(int(t[1]) - q) str int(t[1]) - q int(t[1]) int t[1] t 1 q total_time += q total_time q tasks.append(t) tasks.append tasks append t t = tasks.popleft() tasks.popleft() t total_time += q q total_time tasks = deque(map(lambda x: x.split(), sys.stdin.readlines())) deque(map(lambda x: x.split(), sys.stdin.readlines())) tasks total_time += int(t[1]) int(t[1]) total_time total_time = 0 0 total_time q = map(int, input().split()) map(int, input().split()) q n, q = map(int, input().split()) map(int, input().split()) n
# 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()))

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