# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item)


if __name__ == '__main__':
    solution = Solution()
    solution.message_queue() import sys sys from collections import deque class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) Solution def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) message_queue _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines task_num = int(_input[0].split()[0]) task_num int(_input[0].split()[0]) int _input[0].split()[0] [0].split() [0].split [0] _input 0 split 0 task_time = int(_input[0].split()[1]) task_time int(_input[0].split()[1]) int _input[0].split()[1] [0].split() [0].split [0] _input 0 split 1 total_time = 0 total_time 0 {'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:] for i in _input[1:] i _input[1:] _input 1: 1 for i in _input[1:] {'name': i.split()[0], 'time': int(i.split()[1])} 'name' 'name' i.split()[0] i.split() i.split i split 0 'time' 'time' int(i.split()[1]) int i.split()[1] i.split() i.split i split 1 task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]]) task_deque deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]]) deque [{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]] while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) task_deque item = task_deque.popleft() item task_deque.popleft() task_deque.popleft task_deque popleft if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) item['time'] <= task_time item['time'] item 'time' task_time total_time += item['time'] total_time item['time'] item 'time' print(item['name'], total_time) print item['name'] item 'name' total_time item['time'] -= task_time item['time'] item 'time' task_time total_time += task_time total_time task_time task_deque.append(item) task_deque.append task_deque append item @staticmethod
     message_queue staticmethod message_queue if __name__ == '__main__':
    solution = Solution()
    solution.message_queue() __name__ == '__main__' __name__ '__main__' solution = Solution() solution Solution() Solution solution.message_queue() solution.message_queue solution message_queue solution = Solution() Solution() solution class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item) Solution
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # array_length = int(input())
        _input = sys.stdin.readlines()
        task_num = int(_input[0].split()[0])
        task_time = int(_input[0].split()[1])
        total_time = 0

        task_deque = deque([{'name': i.split()[0], 'time': int(i.split()[1])} for i in _input[1:]])

        while task_deque:
            item = task_deque.popleft()
            if item['time'] <= task_time:
                total_time += item['time']
                print(item['name'], total_time)
            else:
                item['time'] -= task_time
                total_time += task_time
                task_deque.append(item)


if __name__ == '__main__':
    solution = Solution()
    solution.message_queue()