from collections import deque

header = input().split(" ")
N = int(header[0])
q = int(header[1])

queue = deque([])

for i in range(N):
    row = input().split(" ")
    queue.append((row[0], int(row[1])))

totalTime = 0

while queue:
    task = queue.popleft()
    name = task[0]
    time = task[1]
    leftTime = time - q
    if leftTime > 0:
        totalTime += q
        queue.append((name, leftTime))
    else:
        totalTime += time
        print(name + " " + str(totalTime)) from collections import deque header = input().split(" ") header input().split(" ") ().split () input split " " N = int(header[0]) N int(header[0]) int header[0] header 0 q = int(header[1]) q int(header[1]) int header[1] header 1 queue = deque([]) queue deque([]) deque [] for i in range(N):
    row = input().split(" ")
    queue.append((row[0], int(row[1]))) i range(N) range N row = input().split(" ") row input().split(" ") ().split () input split " " queue.append((row[0], int(row[1]))) queue.append queue append (row[0], int(row[1])) row[0] row 0 int(row[1]) int row[1] row 1 totalTime = 0 totalTime 0 while queue:
    task = queue.popleft()
    name = task[0]
    time = task[1]
    leftTime = time - q
    if leftTime > 0:
        totalTime += q
        queue.append((name, leftTime))
    else:
        totalTime += time
        print(name + " " + str(totalTime)) queue task = queue.popleft() task queue.popleft() queue.popleft queue popleft name = task[0] name task[0] task 0 time = task[1] time task[1] task 1 leftTime = time - q leftTime time - q time q if leftTime > 0:
        totalTime += q
        queue.append((name, leftTime))
    else:
        totalTime += time
        print(name + " " + str(totalTime)) leftTime > 0 leftTime 0 totalTime += q totalTime q queue.append((name, leftTime)) queue.append queue append (name, leftTime) name leftTime totalTime += time totalTime time print(name + " " + str(totalTime)) print name + " " + str(totalTime) name + " " name " " str(totalTime) str totalTime header = input().split(" ") input().split(" ") header N = int(header[0]) int(header[0]) N q = int(header[1]) int(header[1]) q row = input().split(" ") input().split(" ") row totalTime = 0 0 totalTime leftTime = time - q time - q leftTime time = task[1] task[1] time queue = deque([]) deque([]) queue name = task[0] task[0] name totalTime += q q totalTime totalTime += time time totalTime task = queue.popleft() queue.popleft() task
from collections import deque

header = input().split(" ")
N = int(header[0])
q = int(header[1])

queue = deque([])

for i in range(N):
    row = input().split(" ")
    queue.append((row[0], int(row[1])))

totalTime = 0

while queue:
    task = queue.popleft()
    name = task[0]
    time = task[1]
    leftTime = time - q
    if leftTime > 0:
        totalTime += q
        queue.append((name, leftTime))
    else:
        totalTime += time
        print(name + " " + str(totalTime))
