#coding:utf-8
#1_3_B
from collections import deque

n, quantum = map(int, input().split())
q = deque()
total_time = 0
for i in range(n):
    name, time = input().split()
    q.append([name, int(time)])

while q:
    ps_name, ps_time = q.popleft()
    if ps_time <= quantum:
        total_time += ps_time
        print(ps_name, total_time)
    else:
        total_time += quantum
        ps_time -= quantum
        q.append([ps_name, ps_time]) from collections import deque n, quantum = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split quantum q = deque() q deque() deque total_time = 0 total_time 0 for i in range(n):
    name, time = input().split()
    q.append([name, int(time)]) i range(n) range n name, time = input().split() name input().split() ().split () input split time q.append([name, int(time)]) q.append q append [name, int(time)] name int(time) int time while q:
    ps_name, ps_time = q.popleft()
    if ps_time <= quantum:
        total_time += ps_time
        print(ps_name, total_time)
    else:
        total_time += quantum
        ps_time -= quantum
        q.append([ps_name, ps_time]) q ps_name, ps_time = q.popleft() ps_name q.popleft() q.popleft q popleft ps_time if ps_time <= quantum:
        total_time += ps_time
        print(ps_name, total_time)
    else:
        total_time += quantum
        ps_time -= quantum
        q.append([ps_name, ps_time]) ps_time <= quantum ps_time quantum total_time += ps_time total_time ps_time print(ps_name, total_time) print ps_name total_time total_time += quantum total_time quantum ps_time -= quantum ps_time quantum q.append([ps_name, ps_time]) q.append q append [ps_name, ps_time] ps_name ps_time n, quantum = map(int, input().split()) map(int, input().split()) n total_time += ps_time ps_time total_time quantum = map(int, input().split()) map(int, input().split()) quantum time = input().split() input().split() time ps_time -= quantum quantum ps_time total_time += quantum quantum total_time ps_name, ps_time = q.popleft() q.popleft() ps_name ps_time = q.popleft() q.popleft() ps_time total_time = 0 0 total_time q = deque() deque() q name, time = input().split() input().split() name
#coding:utf-8
#1_3_B
from collections import deque

n, quantum = map(int, input().split())
q = deque()
total_time = 0
for i in range(n):
    name, time = input().split()
    q.append([name, int(time)])

while q:
    ps_name, ps_time = q.popleft()
    if ps_time <= quantum:
        total_time += ps_time
        print(ps_name, total_time)
    else:
        total_time += quantum
        ps_time -= quantum
        q.append([ps_name, ps_time])