class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array)


def round_robin(quantum, jobs):
    queue = Queue(100000)
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total))


if __name__ == "__main__":
    n, quantum = input().split()
    jobs = [input().split() for i in range(0, int(n))]
    jobs = [(job[0], int(job[1])) for job in jobs]
    round_robin(int(quantum), jobs) class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array) Queue def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

     __init__ if type(_max) != int:
            raise ValueError
         type(_max) != int type(_max) type _max int raise ValueError ValueError None for i in range(0, _max) for i in range(0, _max) i range(0, _max) range 0 _max for i in range(0, _max) None self._array = [None for i in range(0, _max)] self._array self _array [None for i in range(0, _max)] self._head = 0 self._head self _head 0 self._tail = 0 self._tail self _tail 0 self._cnt = 0 self._cnt self _cnt 0 self self _max _max def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

     enqueue if self.is_full():
            raise IndexError
         self.is_full() self.is_full self is_full raise IndexError IndexError self._array[self._head] = value self._array[self._head] self._array self _array self._head self _head value self._cnt += 1 self._cnt self _cnt 1 if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

     self._head + 1 >= len(self._array) self._head + 1 self._head self _head 1 len(self._array) len self._array self _array self._head = 0 self._head self _head 0 self._head += 1 self._head self _head 1 self self value value def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

     dequeue if self.is_empty():
            raise IndexError
         self.is_empty() self.is_empty self is_empty raise IndexError IndexError value = self._array[self._tail] value self._array[self._tail] self._array self _array self._tail self _tail self._cnt -= 1 self._cnt self _cnt 1 if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
         self._tail + 1 >= len(self._array) self._tail + 1 self._tail self _tail 1 len(self._array) len self._array self _array self._tail = 0 self._tail self _tail 0 self._tail += 1 self._tail self _tail 1 return value value self self def is_empty(self):
        return self._cnt <= 0

     is_empty return self._cnt <= 0 self._cnt <= 0 self._cnt self _cnt 0 self self def is_full(self):
        return self._cnt >= len(self._array) is_full return self._cnt >= len(self._array) self._cnt >= len(self._array) self._cnt self _cnt len(self._array) len self._array self _array self self object def round_robin(quantum, jobs):
    queue = Queue(100000)
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total)) round_robin queue = Queue(100000) queue Queue(100000) Queue 100000 total = 0 total 0 for job in jobs:
        queue.enqueue(job)

     job jobs queue.enqueue(job) queue.enqueue queue enqueue job while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total)) not queue.is_empty() queue.is_empty() queue.is_empty queue is_empty name, time = queue.dequeue() name queue.dequeue() queue.dequeue queue dequeue time if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total)) time > quantum time quantum total += quantum total quantum queue.enqueue((name, time - quantum)) queue.enqueue queue enqueue (name, time - quantum) name time - quantum time quantum total += time total time print("{0} {1}".format(name, total)) print "{0} {1}".format(name, total) "{0} {1}".format "{0} {1}" format name total quantum quantum jobs jobs if __name__ == "__main__":
    n, quantum = input().split()
    jobs = [input().split() for i in range(0, int(n))]
    jobs = [(job[0], int(job[1])) for job in jobs]
    round_robin(int(quantum), jobs) __name__ == "__main__" __name__ "__main__" n, quantum = input().split() n input().split() ().split () input split quantum input().split() for i in range(0, int(n)) for i in range(0, int(n)) i range(0, int(n)) range 0 int(n) int n for i in range(0, int(n)) input().split() ().split () input split jobs = [input().split() for i in range(0, int(n))] jobs [input().split() for i in range(0, int(n))] (job[0], int(job[1])) for job in jobs for job in jobs job jobs for job in jobs (job[0], int(job[1])) job[0] job 0 int(job[1]) int job[1] job 1 jobs = [(job[0], int(job[1])) for job in jobs] jobs [(job[0], int(job[1])) for job in jobs] round_robin(int(quantum), jobs) round_robin int(quantum) int quantum jobs jobs = [(job[0], int(job[1])) for job in jobs] [(job[0], int(job[1])) for job in jobs] jobs jobs = [input().split() for i in range(0, int(n))] [input().split() for i in range(0, int(n))] jobs def round_robin(quantum, jobs):
    queue = Queue(100000)
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total)) def round_robin(quantum, jobs):
    queue = Queue(100000)
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total)) round_robin n, quantum = input().split() input().split() n class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array) class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array) Queue quantum = input().split() input().split() quantum
class Queue(object):
    def __init__(self, _max):
        if type(_max) != int:
            raise ValueError
        self._array = [None for i in range(0, _max)]
        self._head = 0
        self._tail = 0
        self._cnt = 0

    def enqueue(self, value):
        if self.is_full():
            raise IndexError
        self._array[self._head] = value
        self._cnt += 1
        if self._head + 1 >= len(self._array):
            self._head = 0
        else:
            self._head += 1

    def dequeue(self):
        if self.is_empty():
            raise IndexError
        value = self._array[self._tail]
        self._cnt -= 1
        if self._tail + 1 >= len(self._array):
            self._tail = 0
        else:
            self._tail += 1
        return value

    def is_empty(self):
        return self._cnt <= 0

    def is_full(self):
        return self._cnt >= len(self._array)


def round_robin(quantum, jobs):
    queue = Queue(100000)
    total = 0
    for job in jobs:
        queue.enqueue(job)

    while not queue.is_empty():
        name, time = queue.dequeue()
        if time > quantum:
            total += quantum
            queue.enqueue((name, time - quantum))
        else:
            total += time
            print("{0} {1}".format(name, total))


if __name__ == "__main__":
    n, quantum = input().split()
    jobs = [input().split() for i in range(0, int(n))]
    jobs = [(job[0], int(job[1])) for job in jobs]
    round_robin(int(quantum), jobs)