using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS1_3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var lineItems = Console.ReadLine().Split(' ');
            var processNums = int.Parse(lineItems[0]);
            var quantum = int.Parse(lineItems[1]);

            List<Process> processes = new List<Process>();
            for(int i = 0; i < processNums; i++)
            {
                lineItems = Console.ReadLine().Split(' ');
                processes.Add(new Process(lineItems[0], int.Parse(lineItems[1])));
            }

            var result = new RoundRobinSchedulingSimulator(quantum, processes).Run();

            foreach(var item in result)
            {
                Console.WriteLine($"{item.Name} {item.Time}");
            }
        }
    }

    public class RoundRobinSchedulingSimulator
    {
        public class SimulatorResultItem
        {
            public string Name { get; private set; }
            public int Time { get; private set; }
            public SimulatorResultItem(string name, int time)
            {
                Name = name;
                Time = time;
            }
        }

        MyQueue<Process> _queue;
        public int Quantum { get; private set; }

        public RoundRobinSchedulingSimulator(int quantum, IEnumerable<Process> processes)
        {
            _queue = new MyQueue<Process>(processes.Count());
            foreach(var p in processes)
            {
                _queue.Enqueue(p);
            }
            Quantum = quantum;
        }
        
        public List<SimulatorResultItem> Run()
        {
            var result = new List<SimulatorResultItem>();
            var totalTime = 0;

            while(!_queue.IsEmpty())
            {
                var p = _queue.Dequeue();
                var remainingTime = p.ProcessingTime - Quantum;
                if(remainingTime <= 0)
                {
                    totalTime += p.ProcessingTime;
                    result.Add(new SimulatorResultItem(p.Name, totalTime));
                }
                else
                {
                    totalTime += Quantum;
                    _queue.Enqueue(new Process(p.Name, remainingTime));
                }
            }

            return result;
        }
    }

    public class Process
    {
        public string Name { get; private set; }
        public int ProcessingTime { get; private set; }

        public Process(string name, int processingTime)
        {
            Name = name;
            ProcessingTime = processingTime;
        }
    }

    public class MyQueue<T>
    {
        private T[] _queue;
        private int _head;
        private int _tail;

        public MyQueue(int size)
        {
            _queue = new T[size + 1];
            _head = -1;
            _tail = 0;
        }

        public void Enqueue(T item)
        {
            _queue[_tail] = item;
            _tail++;
            if(_tail > _queue.Length - 1)
            {
                _tail = 0;
            }

            if(_head == -1)
            {
                _head = 0;
            }
        }

        public T Dequeue()
        {
            if(IsEmpty())
            {
                throw new EmptyException();
            }

            var item = _queue[_head];
            _head++;
            if(_head > _queue.Length - 1)
            {
                _head = 0;
            }

            return item;
        }

        public bool IsEmpty()
        {
            return _head == -1 || _head == _tail;
        }

        public class EmptyException : Exception
        {
            public EmptyException() { }
            public EmptyException(string message) : base(message) { }
            public EmptyException(string message, Exception innerException) : base(message, innerException) { }
        }
    }
}



Measured memory_bytes: 30668