from collections import deque

n , q = map(int,input().split())
p , t = deque() , deque()
for i in range(n):
    x , y = input().split()
    p.append(x)
    t.append(int(y))
time = 0
temp1 = ""
temp2 = 0

while p:
    temp1 , temp2 = p.popleft() , t.popleft()
    if temp2 <= q :
        time += temp2
        print(temp1,time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2) from collections import deque n , q = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split q p , t = deque() , deque() p deque() deque t deque() deque for i in range(n):
    x , y = input().split()
    p.append(x)
    t.append(int(y)) i range(n) range n x , y = input().split() x input().split() ().split () input split y p.append(x) p.append p append x t.append(int(y)) t.append t append int(y) int y time = 0 time 0 temp1 = "" temp1 "" temp2 = 0 temp2 0 while p:
    temp1 , temp2 = p.popleft() , t.popleft()
    if temp2 <= q :
        time += temp2
        print(temp1,time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2) p temp1 , temp2 = p.popleft() , t.popleft() temp1 p.popleft() p.popleft p popleft temp2 t.popleft() t.popleft t popleft if temp2 <= q :
        time += temp2
        print(temp1,time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2) temp2 <= q temp2 q time += temp2 time temp2 print(temp1,time) print temp1 time temp1 , tmep2 = "" , 0 temp1 "" tmep2 0 time += q time q temp2 -= q temp2 q p.append(temp1) p.append p append temp1 t.append(temp2) t.append t append temp2 p , t = deque() , deque() deque() p temp1 , tmep2 = "" , 0 "" temp1 temp2 = 0 0 temp2 temp1 = "" "" temp1 y = input().split() input().split() y n , q = map(int,input().split()) map(int,input().split()) n temp1 , temp2 = p.popleft() , t.popleft() p.popleft() temp1 x , y = input().split() input().split() x temp2 = p.popleft() , t.popleft() t.popleft() temp2 q = map(int,input().split()) map(int,input().split()) q temp2 -= q q temp2 tmep2 = "" , 0 0 tmep2 time += q q time t = deque() , deque() deque() t time += temp2 temp2 time time = 0 0 time
from collections import deque

n , q = map(int,input().split())
p , t = deque() , deque()
for i in range(n):
    x , y = input().split()
    p.append(x)
    t.append(int(y))
time = 0
temp1 = ""
temp2 = 0

while p:
    temp1 , temp2 = p.popleft() , t.popleft()
    if temp2 <= q :
        time += temp2
        print(temp1,time)
        temp1 , tmep2 = "" , 0
    else:
        time += q
        temp2 -= q
        p.append(temp1)
        t.append(temp2)