from queue import deque

def main():
    n, q = tuple(map(int, input().split(' ')))

    task_q = deque()
    for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

    tot_time = 0
    while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time)


main() from queue import deque def main():
    n, q = tuple(map(int, input().split(' ')))

    task_q = deque()
    for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

    tot_time = 0
    while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time) main n, q = tuple(map(int, input().split(' '))) n tuple(map(int, input().split(' '))) tuple map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' q task_q = deque() task_q deque() deque for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

     idx range(n) range n l = input().split(' ') l input().split(' ') ().split () input split ' ' task_q.append((l[0], int(l[1]))) task_q.append task_q append (l[0], int(l[1])) l[0] l 0 int(l[1]) int l[1] l 1 tot_time = 0 tot_time 0 while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time) len(task_q) != 0 len(task_q) len task_q 0 task = task_q.popleft() task task_q.popleft() task_q.popleft task_q popleft if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time) task[1] > q task[1] task 1 q task_q.append((task[0], task[1] - q)) task_q.append task_q append (task[0], task[1] - q) task[0] task 0 task[1] - q task[1] task 1 q tot_time += q tot_time q tot_time += task[1] tot_time task[1] task 1 print(task[0], tot_time) print task[0] task 0 tot_time main() main def main():
    n, q = tuple(map(int, input().split(' ')))

    task_q = deque()
    for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

    tot_time = 0
    while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time) def main():
    n, q = tuple(map(int, input().split(' ')))

    task_q = deque()
    for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

    tot_time = 0
    while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time) main
from queue import deque

def main():
    n, q = tuple(map(int, input().split(' ')))

    task_q = deque()
    for idx in range(n):
        l = input().split(' ')
        task_q.append((l[0], int(l[1])))

    tot_time = 0
    while len(task_q) != 0:

        task = task_q.popleft()
        if task[1] > q:
            task_q.append((task[0], task[1] - q))
            tot_time += q

        else:
            tot_time += task[1]
            print(task[0], tot_time)


main()
