process_num, qms = list(map(int, input().split()))

raw_procs = [eval(input()) for i in range(process_num)]





if __name__ == '__main__':

    procs = []

    for row in raw_procs:

        name, time = row.split()

        procs.append({

            "name": name,

            "time": int(time),

        })



    total_time = 0

    current_proc = 0

    while len(procs) > 0:

        if procs[current_proc]["time"] > qms:

            procs[current_proc]["time"] = procs[current_proc]["time"] - qms

            total_time += qms

            if current_proc == len(procs)-1:

                current_proc = 0

            else:

                current_proc += 1

        else:

            total_time += procs[current_proc]["time"]

            print(("{} {}".format(procs[current_proc]["name"], total_time)))

            del procs[current_proc]

            if current_proc == len(procs):

                current_proc = 0

from collections import deque

 

n,p=list(map(int ,input().split()))

que=deque([])

 

for i in range(n):

    name,time=input().split()

    time=int(time)

    que.append([name,time])

 

t=0

while len(que)>0:

    atop=que.popleft()

    spend=min(atop[1],p)

    atop[1]-=spend

    t+=spend

    if(atop[1]==0):

        print((atop[0],t))

    else:

        que.append(atop)

process_num, qms = list(map(int, input().split()))
raw_procs = [eval(input()) for i in range(process_num)]
if __name__ == "__main__":
    procs = []
    for row in raw_procs:
        name, time = row.split()
        procs.append(
            {
                "name": name,
                "time": int(time),
            }
        )
    total_time = 0
    current_proc = 0
    while len(procs) > 0:
        if procs[current_proc]["time"] > qms:
            procs[current_proc]["time"] = procs[current_proc]["time"] - qms
            total_time += qms
            if current_proc == len(procs) - 1:
                current_proc = 0
            else:
                current_proc += 1
        else:
            total_time += procs[current_proc]["time"]
            print(("{} {}".format(procs[current_proc]["name"], total_time)))
            del procs[current_proc]
            if current_proc == len(procs):
                current_proc = 0

from collections import deque

n, p = list(map(int, input().split()))
que = deque([])
for i in range(n):
    name, time = input().split()
    time = int(time)
    que.append([name, time])
t = 0
while len(que) > 0:
    atop = que.popleft()
    spend = min(atop[1], p)
    atop[1] -= spend
    t += spend
    if atop[1] == 0:
        print((atop[0], t))
    else:
        que.append(atop)

-process_num, qms = list(map(int, input().split())) -raw_procs = [eval(input()) for i in range(process_num)] -if __name__ == "__main__": -    procs = [] -    for row in raw_procs: -        name, time = row.split() -        procs.append( -            { -                "name": name, -                "time": int(time), -            } -        ) -    total_time = 0 -    current_proc = 0 -    while len(procs) > 0: -        if procs[current_proc]["time"] > qms: -            procs[current_proc]["time"] = procs[current_proc]["time"] - qms -            total_time += qms -            if current_proc == len(procs) - 1: -                current_proc = 0 -            else: -                current_proc += 1 -        else: -            total_time += procs[current_proc]["time"] -            print(("{} {}".format(procs[current_proc]["name"], total_time))) -            del procs[current_proc] -            if current_proc == len(procs): -                current_proc = 0 +from collections import deque + +n, p = list(map(int, input().split())) +que = deque([]) +for i in range(n): +    name, time = input().split() +    time = int(time) +    que.append([name, time]) +t = 0 +while len(que) > 0: +    atop = que.popleft() +    spend = min(atop[1], p) +    atop[1] -= spend +    t += spend +    if atop[1] == 0: +        print((atop[0], t)) +    else: +        que.append(atop)