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