#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ?????\??? '''

# ?¨??????????O(1)


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

    while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

    return result


if __name__ == '__main__':
    N_p, quantum = map(int, input().split())
    p_name, p_time = [], []
    for i in range(N_p):
        p = list(input().split())
        p_name.append(p[0])
        p_time.append(int(p[1]))

    result = round_robin_scheduling(p_name, p_time, quantum)

    for i in range(len(result)):
        print(result[i]) ''' ?????\??? ''' def round_robin_scheduling(process_name, process_time, quantum):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

    return result round_robin_scheduling result = [] result [] elapsed_time = 0 elapsed_time 0 while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

     len(process_name) > 0 len(process_name) len process_name 0 p_name = process_name.pop(0) p_name process_name.pop(0) process_name.pop process_name pop 0 p_time = process_time.pop(0) p_time process_time.pop(0) process_time.pop process_time pop 0 if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

     p_time > quantum p_time quantum elapsed_time += quantum elapsed_time quantum process_name.append(p_name) process_name.append process_name append p_name process_time.append(p_time - quantum) process_time.append process_time append p_time - quantum p_time quantum elapsed_time += p_time elapsed_time p_time result.append(p_name + ' ' + str(elapsed_time)) result.append result append p_name + ' ' + str(elapsed_time) p_name + ' ' p_name ' ' str(elapsed_time) str elapsed_time return result result process_name process_name process_time process_time quantum quantum if __name__ == '__main__':
    N_p, quantum = map(int, input().split())
    p_name, p_time = [], []
    for i in range(N_p):
        p = list(input().split())
        p_name.append(p[0])
        p_time.append(int(p[1]))

    result = round_robin_scheduling(p_name, p_time, quantum)

    for i in range(len(result)):
        print(result[i]) __name__ == '__main__' __name__ '__main__' N_p, quantum = map(int, input().split()) N_p map(int, input().split()) map int input().split() ().split () input split quantum p_name, p_time = [], [] p_name [] p_time [] for i in range(N_p):
        p = list(input().split())
        p_name.append(p[0])
        p_time.append(int(p[1]))

     i range(N_p) range N_p p = list(input().split()) p list(input().split()) list input().split() ().split () input split p_name.append(p[0]) p_name.append p_name append p[0] p 0 p_time.append(int(p[1])) p_time.append p_time append int(p[1]) int p[1] p 1 result = round_robin_scheduling(p_name, p_time, quantum) result round_robin_scheduling(p_name, p_time, quantum) round_robin_scheduling p_name p_time quantum for i in range(len(result)):
        print(result[i]) i range(len(result)) range len(result) len result print(result[i]) print result[i] result i def round_robin_scheduling(process_name, process_time, quantum):
    result = []
    elapsed_time = 0

    while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

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

    while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

    return result round_robin_scheduling result = round_robin_scheduling(p_name, p_time, quantum) round_robin_scheduling(p_name, p_time, quantum) result quantum = map(int, input().split()) map(int, input().split()) quantum p_name, p_time = [], [] [] p_name p_time = [], [] [] p_time N_p, quantum = map(int, input().split()) map(int, input().split()) N_p p = list(input().split()) list(input().split()) p
#! /usr/bin/env python
# -*- coding: utf-8 -*-

''' ?????\??? '''

# ?¨??????????O(1)


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

    while len(process_name) > 0:
        p_name = process_name.pop(0)
        p_time = process_time.pop(0)

        if p_time > quantum:
            elapsed_time += quantum
            process_name.append(p_name)
            process_time.append(p_time - quantum)
        else:
            elapsed_time += p_time
            result.append(p_name + ' ' + str(elapsed_time))

    return result


if __name__ == '__main__':
    N_p, quantum = map(int, input().split())
    p_name, p_time = [], []
    for i in range(N_p):
        p = list(input().split())
        p_name.append(p[0])
        p_time.append(int(p[1]))

    result = round_robin_scheduling(p_name, p_time, quantum)

    for i in range(len(result)):
        print(result[i])