# -*- coding: utf-8 -*-

import sys
import os
from queue import Queue


N, Q = list(map(int, input().split()))

q = Queue()
for i in range(N):
    lst = input().split()
    name = lst[0]
    t = int(lst[1])
    data = [name, t]
    q.put(data)

time = 0
while not q.empty():
    data = q.get()
    if data[1] > Q:
        data[1] -= Q
        q.put(data)
        time += Q
    else:
        time += data[1]
        print(data[0], time) import sys sys import os os from queue import Queue N, Q = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split Q q = Queue() q Queue() Queue for i in range(N):
    lst = input().split()
    name = lst[0]
    t = int(lst[1])
    data = [name, t]
    q.put(data) i range(N) range N lst = input().split() lst input().split() ().split () input split name = lst[0] name lst[0] lst 0 t = int(lst[1]) t int(lst[1]) int lst[1] lst 1 data = [name, t] data [name, t] name t q.put(data) q.put q put data time = 0 time 0 while not q.empty():
    data = q.get()
    if data[1] > Q:
        data[1] -= Q
        q.put(data)
        time += Q
    else:
        time += data[1]
        print(data[0], time) not q.empty() q.empty() q.empty q empty data = q.get() data q.get() q.get q get if data[1] > Q:
        data[1] -= Q
        q.put(data)
        time += Q
    else:
        time += data[1]
        print(data[0], time) data[1] > Q data[1] data 1 Q data[1] -= Q data[1] data 1 Q q.put(data) q.put q put data time += Q time Q time += data[1] time data[1] data 1 print(data[0], time) print data[0] data 0 time q = Queue() Queue() q time += Q Q time time = 0 0 time data = q.get() q.get() data name = lst[0] lst[0] name data = [name, t] [name, t] data time += data[1] data[1] time Q = list(map(int, input().split())) list(map(int, input().split())) Q N, Q = list(map(int, input().split())) list(map(int, input().split())) N lst = input().split() input().split() lst t = int(lst[1]) int(lst[1]) t
# -*- coding: utf-8 -*-

import sys
import os
from queue import Queue


N, Q = list(map(int, input().split()))

q = Queue()
for i in range(N):
    lst = input().split()
    name = lst[0]
    t = int(lst[1])
    data = [name, t]
    q.put(data)

time = 0
while not q.empty():
    data = q.get()
    if data[1] > Q:
        data[1] -= Q
        q.put(data)
        time += Q
    else:
        time += data[1]
        print(data[0], time)