_n_ _q_   _name 1 time1_   _name 2 time2_   ...   _name n timen_    In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space.  In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.

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
        print("ended",time,result)
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)
        print("continue",name,q)


for i in range(number):
    print(result[i][0],result[i][1])







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])





