from collections import deque
 
process_num, qms = map(int ,input().split())
que = deque({})
 
for i in range(process_num):
    name, time = input().split()
    time = int(time)
    que.append({"name":name, "time":time})
 
if __name__ == '__main__':
    total_time = 0
    while len(que)>0:
        atop = que.popleft()
        spend = min(atop["time"], qms)
        atop["time"] -= spend
        total_time += spend
        if(atop["time"] == 0):
            print("{} {}".format(atop["name"], total_time))
        else:
            que.append(atop)
 from collections import deque process_num, qms = map(int ,input().split()) process_num map(int ,input().split()) map int input().split() ().split () input split qms que = deque({}) que deque({}) deque {} for i in range(process_num):
    name, time = input().split()
    time = int(time)
    que.append({"name":name, "time":time})
  i range(process_num) range process_num name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time que.append({"name":name, "time":time}) que.append que append {"name":name, "time":time} "name" "name" name "time" "time" time if __name__ == '__main__':
    total_time = 0
    while len(que)>0:
        atop = que.popleft()
        spend = min(atop["time"], qms)
        atop["time"] -= spend
        total_time += spend
        if(atop["time"] == 0):
            print("{} {}".format(atop["name"], total_time))
        else:
            que.append(atop) __name__ == '__main__' __name__ '__main__' total_time = 0 total_time 0 while len(que)>0:
        atop = que.popleft()
        spend = min(atop["time"], qms)
        atop["time"] -= spend
        total_time += spend
        if(atop["time"] == 0):
            print("{} {}".format(atop["name"], total_time))
        else:
            que.append(atop) len(que)>0 len(que) len que 0 atop = que.popleft() atop que.popleft() que.popleft que popleft spend = min(atop["time"], qms) spend min(atop["time"], qms) min atop["time"] atop "time" qms atop["time"] -= spend atop["time"] atop "time" spend total_time += spend total_time spend if(atop["time"] == 0):
            print("{} {}".format(atop["name"], total_time))
        else:
            que.append(atop) atop["time"] == 0 atop["time"] atop "time" 0 print("{} {}".format(atop["name"], total_time)) print "{} {}".format(atop["name"], total_time) "{} {}".format "{} {}" format atop["name"] atop "name" total_time que.append(atop) que.append que append atop process_num, qms = map(int ,input().split()) map(int ,input().split()) process_num total_time = 0 0 total_time spend = min(atop["time"], qms) min(atop["time"], qms) spend total_time += spend spend total_time name, time = input().split() input().split() name time = int(time) int(time) time atop = que.popleft() que.popleft() atop time = input().split() input().split() time qms = map(int ,input().split()) map(int ,input().split()) qms que = deque({}) deque({}) que
from collections import deque
 
process_num, qms = map(int ,input().split())
que = deque({})
 
for i in range(process_num):
    name, time = input().split()
    time = int(time)
    que.append({"name":name, "time":time})
 
if __name__ == '__main__':
    total_time = 0
    while len(que)>0:
        atop = que.popleft()
        spend = min(atop["time"], qms)
        atop["time"] -= spend
        total_time += spend
        if(atop["time"] == 0):
            print("{} {}".format(atop["name"], total_time))
        else:
            que.append(atop)

