# encoding: utf-8

import sys
from collections import deque

input_ = sys.stdin.readlines()


def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time])


message_queue() import sys sys from collections import deque input_ = sys.stdin.readlines() input_ sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time]) message_queue n, shard = map(int, input_[0].split()) n map(int, input_[0].split()) map int input_[0].split() [0].split [0] input_ 0 split shard task_deque = deque(map(lambda x: x.split(), input_[1:])) task_deque deque(map(lambda x: x.split(), input_[1:])) deque map(lambda x: x.split(), input_[1:]) map lambda x: x.split() x.split() x.split x split x input_[1:] input_ 1: 1 t_accu = 0 t_accu 0 while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time]) task_deque t_name, t_time = task_deque.popleft() t_name task_deque.popleft() task_deque.popleft task_deque popleft t_time t_time = int(t_time) t_time int(t_time) int t_time if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time]) t_time <= shard t_time shard t_accu += t_time t_accu t_time print(t_name, t_accu) print t_name t_accu t_time -= shard t_time shard t_accu += shard t_accu shard task_deque.append([t_name, t_time]) task_deque.append task_deque append [t_name, t_time] t_name t_time message_queue() message_queue input_ = sys.stdin.readlines() sys.stdin.readlines() input_ def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time]) def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time]) message_queue
# encoding: utf-8

import sys
from collections import deque

input_ = sys.stdin.readlines()


def message_queue():
    # write your code here
    n, shard = map(int, input_[0].split())

    task_deque = deque(map(lambda x: x.split(), input_[1:]))
    t_accu = 0

    while task_deque:
        t_name, t_time = task_deque.popleft()
        t_time = int(t_time)
        if t_time <= shard:
            t_accu += t_time
            print(t_name, t_accu)
        else:
            t_time -= shard
            t_accu += shard
            task_deque.append([t_name, t_time])


message_queue()