from collections import namedtuple

Task = namedtuple('Task', 'name time')

class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._tail == self.n

if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n+1)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q))
 from collections import namedtuple Task = namedtuple('Task', 'name time') Task namedtuple('Task', 'name time') namedtuple 'Task' 'name time' class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._tail == self.n Queue def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

     __init__ self.n = n self.n self n n None for _ in range(self.n + 1) for _ in range(self.n + 1) _ range(self.n + 1) range self.n + 1 self.n self n 1 for _ in range(self.n + 1) None self._l = [None for _ in range(self.n + 1)] self._l self _l [None for _ in range(self.n + 1)] self._head = 0 self._head self _head 0 self._tail = 0 self._tail self _tail 0 self self n n def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

     enqueue self._l[self._tail] = x self._l[self._tail] self._l self _l self._tail self _tail x self._tail += 1 self._tail self _tail 1 if self._tail > self.n:
            self._tail -= self.n

     self._tail > self.n self._tail self _tail self.n self n self._tail -= self.n self._tail self _tail self.n self n self self x x def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

     dequeue if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

     self.isEmpty() self.isEmpty self isEmpty raise IndexError("pop from empty queue") IndexError("pop from empty queue") IndexError "pop from empty queue" e = self._l[self._head] e self._l[self._head] self._l self _l self._head self _head self._l[self._head] = None self._l[self._head] self._l self _l self._head self _head None self._head += 1 self._head self _head 1 if self._head > self.n:
                self._head -= self.n
             self._head > self.n self._head self _head self.n self n self._head -= self.n self._head self _head self.n self n return e e self self def isEmpty(self):
        return self._head == self._tail

     isEmpty return self._head == self._tail self._head == self._tail self._head self _head self._tail self _tail self self def isFull(self):
        return self._tail == self.n isFull return self._tail == self.n self._tail == self.n self._tail self _tail self.n self n self self if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n+1)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q)) __name__ == '__main__' __name__ '__main__' n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q queue = Queue(n+1) queue Queue(n+1) Queue n+1 n 1 for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

     _ range(n) range n name, time = input().split() name input().split() ().split () input split time time = int(time) time int(time) int time queue.enqueue(Task(name=name, time=time)) queue.enqueue queue enqueue Task(name=name, time=time) Task name=name name name time=time time time now = 0 now 0 while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q)) not queue.isEmpty() queue.isEmpty() queue.isEmpty queue isEmpty task = queue.dequeue() task queue.dequeue() queue.dequeue queue dequeue t = task.time t task.time task time if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q)) t <= q t q now += t now t print(task.name, now) print task.name task name now now += q now q queue.enqueue(Task(task.name, t - q)) queue.enqueue queue enqueue Task(task.name, t - q) Task task.name task name t - q t q Task = namedtuple('Task', 'name time') namedtuple('Task', 'name time') Task q = map(int, input().split()) map(int, input().split()) q now += q q now name, time = input().split() input().split() name time = input().split() input().split() time time = int(time) int(time) time n, q = map(int, input().split()) map(int, input().split()) n now += t t now now = 0 0 now t = task.time task.time t queue = Queue(n+1) Queue(n+1) queue class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._tail == self.n class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._tail == self.n Queue task = queue.dequeue() queue.dequeue() task
from collections import namedtuple

Task = namedtuple('Task', 'name time')

class Queue:
    def __init__(self, n):
        self.n = n
        self._l = [None for _ in range(self.n + 1)]
        self._head = 0
        self._tail = 0

    def enqueue(self, x):
        self._l[self._tail] = x
        self._tail += 1
        if self._tail > self.n:
            self._tail -= self.n

    def dequeue(self):
        if self.isEmpty():
            raise IndexError("pop from empty queue")
        else:
            e = self._l[self._head]
            self._l[self._head] = None
            self._head += 1
            if self._head > self.n:
                self._head -= self.n
            return e

    def isEmpty(self):
        return self._head == self._tail

    def isFull(self):
        return self._tail == self.n

if __name__ == '__main__':
    n, q = map(int, input().split())
    queue = Queue(n+1)
    for _ in range(n):
        name, time = input().split()
        time = int(time)
        queue.enqueue(Task(name=name, time=time))

    now = 0
    while not queue.isEmpty():
        task = queue.dequeue()
        t = task.time
        if t <= q:
            now += t
            print(task.name, now)
        else:
            now += q
            queue.enqueue(Task(task.name, t - q))

