# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def message_queue():
        # write your code here
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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 task_num, task_time = map(int, input().split()) task_num map(int, input().split()) map int input().split() ().split () input split task_time _input = sys.stdin.readlines() _input sys.stdin.readlines() sys.stdin.readlines sys.stdin sys stdin readlines task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input)) task_deque deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input)) deque map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input) map lambda x: dict(name=x.split()[0], time=int(x.split()[-1])) dict(name=x.split()[0], time=int(x.split()[-1])) dict name=x.split()[0] name x.split()[0] x.split() x.split x split 0 time=int(x.split()[-1]) time int(x.split()[-1]) int x.split()[-1] x.split() x.split x split -1 x _input total_time = 0 total_time 0 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
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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
        # tasks = deque(map(lambda x: x.split(), sys.stdin.readlines()))
        task_num, task_time = map(int, input().split())
        _input = sys.stdin.readlines()
        
        task_deque = deque(map(lambda x: dict(name=x.split()[0], time=int(x.split()[-1])), _input))
        total_time = 0

        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()