class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0)

class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime)


def rr(queue, q):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task)

if __name__ == '__main__':
    nq = [int(s) for s in input().split()]
    N = nq[0]
    q = nq[1]
    queue = Queue()
    task_arr = [Task(*input().split()) for i in range(N)]
    for t in task_arr:
        queue.enqueue(t)
    rr(queue, q) class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0) Queue def __init__(self):
        self.queue = []

     __init__ self.queue = [] self.queue self queue [] self self def enqueue(self, value):
        self.queue.append(value)

     enqueue self.queue.append(value) self.queue.append self.queue self queue append value self self value value def dequeue(self):
        return self.queue.pop(0) dequeue return self.queue.pop(0) self.queue.pop(0) self.queue.pop self.queue self queue pop 0 self self class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime) Task def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

     __init__ self.name = name self.name self name name self.time = int(time) self.time self time int(time) int time self.endtime = 0 self.endtime self endtime 0 self self name name time time def __repr__(self):
        return '{} {}'.format(self.name, self.endtime) __repr__ return '{} {}'.format(self.name, self.endtime) '{} {}'.format(self.name, self.endtime) '{} {}'.format '{} {}' format self.name self name self.endtime self endtime self self def rr(queue, q):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task) rr time = 0 time 0 while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task) len(queue.queue) > 0 len(queue.queue) len queue.queue queue queue 0 task = queue.dequeue() task queue.dequeue() queue.dequeue queue dequeue if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task) task.time > q task.time task time q task.time -= q task.time task time q time += q time q queue.enqueue(task) queue.enqueue queue enqueue task time += task.time time task.time task time task.time = 0 task.time task time 0 task.endtime = time task.endtime task endtime time print(task) print task queue queue q q if __name__ == '__main__':
    nq = [int(s) for s in input().split()]
    N = nq[0]
    q = nq[1]
    queue = Queue()
    task_arr = [Task(*input().split()) for i in range(N)]
    for t in task_arr:
        queue.enqueue(t)
    rr(queue, q) __name__ == '__main__' __name__ '__main__' int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s nq = [int(s) for s in input().split()] nq [int(s) for s in input().split()] N = nq[0] N nq[0] nq 0 q = nq[1] q nq[1] nq 1 queue = Queue() queue Queue() Queue Task(*input().split()) for i in range(N) for i in range(N) i range(N) range N for i in range(N) Task(*input().split()) Task *input().split() input().split() ().split () input split task_arr = [Task(*input().split()) for i in range(N)] task_arr [Task(*input().split()) for i in range(N)] for t in task_arr:
        queue.enqueue(t)
     t task_arr queue.enqueue(t) queue.enqueue queue enqueue t rr(queue, q) rr queue q task_arr = [Task(*input().split()) for i in range(N)] [Task(*input().split()) for i in range(N)] task_arr class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0) class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0) Queue nq = [int(s) for s in input().split()] [int(s) for s in input().split()] nq def rr(queue, q):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task) def rr(queue, q):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task) rr queue = Queue() Queue() queue class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime) class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime) Task q = nq[1] nq[1] q N = nq[0] nq[0] N
class Queue:
    def __init__(self):
        self.queue = []

    def enqueue(self, value):
        self.queue.append(value)

    def dequeue(self):
        return self.queue.pop(0)

class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = int(time)
        self.endtime = 0

    def __repr__(self):
        return '{} {}'.format(self.name, self.endtime)


def rr(queue, q):
    time = 0
    while len(queue.queue) > 0:
        task = queue.dequeue()
        if task.time > q:
            task.time -= q
            time += q
            queue.enqueue(task)
        else:
            time += task.time
            task.time = 0
            task.endtime = time
            print(task)

if __name__ == '__main__':
    nq = [int(s) for s in input().split()]
    N = nq[0]
    q = nq[1]
    queue = Queue()
    task_arr = [Task(*input().split()) for i in range(N)]
    for t in task_arr:
        queue.enqueue(t)
    rr(queue, q)