_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

dq = collections.deque()
N, Q = map(int, input().split())
for i in range(N):
    name, time = input().split()
    dq.append((name, int(time)))
total_time = 0
while dq:
    name, time = dq.popleft()
    total_time += min(Q, time)
    if time <= Q:
        print(name, total_time)
    else:
        dq.append((name, time))
import collections

dq = collections.deque()
N, Q = map(int, input().split())
for i in range(N):
    name, time = input().split()
    dq.append((name, int(time)))
total_time = 0
while dq:
    name, time = dq.popleft()
    total_time += min(Q, time)
    if time <= Q:
        print(name, total_time)
    else:
        dq.append((name, time-Q))