# -*- coding: utf-8 -*-


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i] def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result round_robin_scheduling result = [] result [] elapsed_time = 0 elapsed_time 0 while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
     len(process_name) > 0 len(process_name) len process_name 0 if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
     process_time[0] <= q process_time[0] process_time 0 q elapsed_time += process_time[0] elapsed_time process_time[0] process_time 0 process_time.pop(0) process_time.pop process_time pop 0 result.append(process_name.pop(0) + ' ' + str(elapsed_time)) result.append result append process_name.pop(0) + ' ' + str(elapsed_time) process_name.pop(0) + ' ' process_name.pop(0) process_name.pop process_name pop 0 ' ' str(elapsed_time) str elapsed_time elapsed_time += q elapsed_time q process_name.append(process_name.pop(0)) process_name.append process_name append process_name.pop(0) process_name.pop process_name pop 0 process_time.append(process_time.pop(0) - q) process_time.append process_time append process_time.pop(0) - q process_time.pop(0) process_time.pop process_time pop 0 q return result result process_name process_name process_time process_time q q if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i] __name__ == '__main__' __name__ '__main__' N, q = map(int, raw_input().split()) N map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q process_name, process_time = [], [] process_name [] process_time [] for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
     i xrange(N) xrange N process = raw_input().split() process raw_input().split() ().split () raw_input split process_name.append(process[0]) process_name.append process_name append process[0] process 0 process_time.append(int(process[1])) process_time.append process_time append int(process[1]) int process[1] process 1 result = round_robin_scheduling(process_name, process_time, q) result round_robin_scheduling(process_name, process_time, q) round_robin_scheduling process_name process_time q for i in xrange(len(result)):
        print result[i] i xrange(len(result)) xrange len(result) len result print result[i] result i process_time = [], [] [] process_time result = round_robin_scheduling(process_name, process_time, q) round_robin_scheduling(process_name, process_time, q) result def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result round_robin_scheduling process_name, process_time = [], [] [] process_name process = raw_input().split() raw_input().split() process N, q = map(int, raw_input().split()) map(int, raw_input().split()) N q = map(int, raw_input().split()) map(int, raw_input().split()) q
# -*- coding: utf-8 -*-


def round_robin_scheduling(process_name, process_time, q):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        # print process_name
        # print process_time
        if process_time[0] <= q:
            elapsed_time += process_time[0]
            process_time.pop(0)
            result.append(process_name.pop(0) + ' ' + str(elapsed_time))
        else:
            elapsed_time += q
            process_name.append(process_name.pop(0))
            process_time.append(process_time.pop(0) - q)
    return result


if __name__ == '__main__':
    N, q = map(int, raw_input().split())
    process_name, process_time = [], []
    for i in xrange(N):
        process = raw_input().split()
        process_name.append(process[0])
        process_time.append(int(process[1]))
    # N, q = 5, 100
    # process_name = ['p1', 'p2', 'p3', 'p4', 'p5']
    # process_time = [150, 80, 200, 350, 20]
    result = round_robin_scheduling(process_name, process_time, q)
    for i in xrange(len(result)):
        print result[i]