#getting input
statements = []
while True:
    try:
        line = str(input())
    except EOFError:
        break
    statements.append(line)

pair = statements.pop(0).split()
amount = int(pair[0])
quantum = int(pair[1])

#process input
queue = []
for state in statements:
    pair = state.split()
    name = pair[0]
    time = int(pair[1])
    queue.append([name,time])

#processing queue

done_list = list()
time_spend = 0
while True:
    if not len(queue) > 0:
        break
    task = queue[0]


    if task[1] >= quantum: #time left
        time_spend += quantum
        task[1] = task[1] - quantum
    else:
        time_spend += task[1]
        task[1] = 0

    if task[1] <= 0: #finished
        task.append(time_spend)   #name,left_time, finished time
        done_list.append((task[0],task[2])) #name and finished time
        queue.remove(task)
    else:
        temp = task
        queue.remove(task)
        queue.append(temp)

for result in done_list:
    print(result[0],end=' ')
    print(result[1]) statements = [] statements [] while True:
    try:
        line = str(input())
    except EOFError:
        break
    statements.append(line) True try:
        line = str(input())
    except EOFError:
        break
     except EOFError:
        break
     break line = str(input()) line str(input()) str input() input statements.append(line) statements.append statements append line pair = statements.pop(0).split() pair statements.pop(0).split() statements.pop(0).split statements.pop(0) statements.pop statements pop 0 split amount = int(pair[0]) amount int(pair[0]) int pair[0] pair 0 quantum = int(pair[1]) quantum int(pair[1]) int pair[1] pair 1 queue = [] queue [] for state in statements:
    pair = state.split()
    name = pair[0]
    time = int(pair[1])
    queue.append([name,time])

#processing queue state statements pair = state.split() pair state.split() state.split state split name = pair[0] name pair[0] pair 0 time = int(pair[1]) time int(pair[1]) int pair[1] pair 1 queue.append([name,time]) queue.append queue append [name,time] name time done_list = list() done_list list() list time_spend = 0 time_spend 0 while True:
    if not len(queue) > 0:
        break
    task = queue[0]


    if task[1] >= quantum: #time left
        time_spend += quantum
        task[1] = task[1] - quantum
    else:
        time_spend += task[1]
        task[1] = 0

    if task[1] <= 0: #finished
        task.append(time_spend)   #name,left_time, finished time
        done_list.append((task[0],task[2])) #name and finished time
        queue.remove(task)
    else:
        temp = task
        queue.remove(task)
        queue.append(temp) True if not len(queue) > 0:
        break
     not len(queue) > 0 len(queue) > 0 len(queue) len queue 0 break task = queue[0] task queue[0] queue 0 if task[1] >= quantum: #time left
        time_spend += quantum
        task[1] = task[1] - quantum
    else:
        time_spend += task[1]
        task[1] = 0

     task[1] >= quantum task[1] task 1 quantum time_spend += quantum time_spend quantum task[1] = task[1] - quantum task[1] task 1 task[1] - quantum task[1] task 1 quantum time_spend += task[1] time_spend task[1] task 1 task[1] = 0 task[1] task 1 0 if task[1] <= 0: #finished
        task.append(time_spend)   #name,left_time, finished time
        done_list.append((task[0],task[2])) #name and finished time
        queue.remove(task)
    else:
        temp = task
        queue.remove(task)
        queue.append(temp) task[1] <= 0 task[1] task 1 0 task.append(time_spend) task.append task append time_spend done_list.append((task[0],task[2])) done_list.append done_list append (task[0],task[2]) task[0] task 0 task[2] task 2 queue.remove(task) queue.remove queue remove task temp = task temp task queue.remove(task) queue.remove queue remove task queue.append(temp) queue.append queue append temp for result in done_list:
    print(result[0],end=' ')
    print(result[1]) result done_list print(result[0],end=' ') print result[0] result 0 end=' ' end ' ' print(result[1]) print result[1] result 1 statements = [] [] statements quantum = int(pair[1]) int(pair[1]) quantum task = queue[0] queue[0] task queue = [] [] queue name = pair[0] pair[0] name time = int(pair[1]) int(pair[1]) time time_spend += quantum quantum time_spend pair = state.split() state.split() pair temp = task task temp time_spend = 0 0 time_spend line = str(input()) str(input()) line amount = int(pair[0]) int(pair[0]) amount done_list = list() list() done_list time_spend += task[1] task[1] time_spend pair = statements.pop(0).split() statements.pop(0).split() pair
#getting input
statements = []
while True:
    try:
        line = str(input())
    except EOFError:
        break
    statements.append(line)

pair = statements.pop(0).split()
amount = int(pair[0])
quantum = int(pair[1])

#process input
queue = []
for state in statements:
    pair = state.split()
    name = pair[0]
    time = int(pair[1])
    queue.append([name,time])

#processing queue

done_list = list()
time_spend = 0
while True:
    if not len(queue) > 0:
        break
    task = queue[0]


    if task[1] >= quantum: #time left
        time_spend += quantum
        task[1] = task[1] - quantum
    else:
        time_spend += task[1]
        task[1] = 0

    if task[1] <= 0: #finished
        task.append(time_spend)   #name,left_time, finished time
        done_list.append((task[0],task[2])) #name and finished time
        queue.remove(task)
    else:
        temp = task
        queue.remove(task)
        queue.append(temp)

for result in done_list:
    print(result[0],end=' ')
    print(result[1])
