
import collections
#データの入力
a=input().split()

number=int(a[0])
quantum=int(a[1])

#保持データの作成
time=0

#キューの作成
name=[]
name=collections.deque()
q=[]
q=collections.deque()

#結果の保持
result=[[0 for i in range(2)]for j in range(number)]
endednumber=0

totaltime=0

for i in range(number):
    b=input().split()
    name.append(b[0])
    q.append(int(b[1]))
    totaltime+=int(b[1])

#キューの処理
while totaltime>time:
    cn=name.popleft()
    cq=q.popleft()

    if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)

#結果の表示
for i in range(number):
    print(result[i][0],result[i][1])




 import collections collections a=input().split() a input().split() ().split () input split number=int(a[0]) number int(a[0]) int a[0] a 0 quantum=int(a[1]) quantum int(a[1]) int a[1] a 1 time=0 time 0 name=[] name [] name=collections.deque() name collections.deque() collections.deque collections deque q=[] q [] q=collections.deque() q collections.deque() collections.deque collections deque [0 for i in range(2)]for j in range(number) for j in range(number) j range(number) range number for j in range(number) [0 for i in range(2)] result=[[0 for i in range(2)]for j in range(number)] result [[0 for i in range(2)]for j in range(number)] endednumber=0 endednumber 0 totaltime=0 totaltime 0 for i in range(number):
    b=input().split()
    name.append(b[0])
    q.append(int(b[1]))
    totaltime+=int(b[1])

#キューの処理 i range(number) range number b=input().split() b input().split() ().split () input split name.append(b[0]) name.append name append b[0] b 0 q.append(int(b[1])) q.append q append int(b[1]) int b[1] b 1 totaltime+=int(b[1]) totaltime int(b[1]) int b[1] b 1 while totaltime>time:
    cn=name.popleft()
    cq=q.popleft()

    if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)

#結果の表示 totaltime>time totaltime time cn=name.popleft() cn name.popleft() name.popleft name popleft cq=q.popleft() cq q.popleft() q.popleft q popleft if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)

#結果の表示 cq<=quantum cq quantum time+=cq time cq result[endednumber][0]=cn result[endednumber][0] [endednumber] result endednumber 0 cn result[endednumber][1]=time result[endednumber][1] [endednumber] result endednumber 1 time endednumber+=1 endednumber 1 time+=quantum time quantum newq=cq-quantum newq cq-quantum cq quantum name.append(cn) name.append name append cn q.append(newq) q.append q append newq for i in range(number):
    print(result[i][0],result[i][1]) i range(number) range number print(result[i][0],result[i][1]) print result[i][0] [i] result i 0 result[i][1] [i] result i 1 q=[] [] q name=[] [] name name=collections.deque() collections.deque() name totaltime+=int(b[1]) int(b[1]) totaltime result=[[0 for i in range(2)]for j in range(number)] [[0 for i in range(2)]for j in range(number)] result cq=q.popleft() q.popleft() cq endednumber+=1 1 endednumber q=collections.deque() collections.deque() q quantum=int(a[1]) int(a[1]) quantum newq=cq-quantum cq-quantum newq cn=name.popleft() name.popleft() cn b=input().split() input().split() b a=input().split() input().split() a totaltime=0 0 totaltime time+=cq cq time time+=quantum quantum time number=int(a[0]) int(a[0]) number time=0 0 time endednumber=0 0 endednumber

import collections
#データの入力
a=input().split()

number=int(a[0])
quantum=int(a[1])

#保持データの作成
time=0

#キューの作成
name=[]
name=collections.deque()
q=[]
q=collections.deque()

#結果の保持
result=[[0 for i in range(2)]for j in range(number)]
endednumber=0

totaltime=0

for i in range(number):
    b=input().split()
    name.append(b[0])
    q.append(int(b[1]))
    totaltime+=int(b[1])

#キューの処理
while totaltime>time:
    cn=name.popleft()
    cq=q.popleft()

    if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)

#結果の表示
for i in range(number):
    print(result[i][0],result[i][1])





