class Process_Queue:
    class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

    def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

    def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

    def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None

n, q = map(int, input().split())

p_queue = Process_Queue(q)

for i in range(n):
    p = input().split()
    p_queue.enqueue(p[0], int(p[1]))

while not p_queue.front == p_queue.rear == None:
    p_queue.dequeue() class Process_Queue:
    class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

    def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

    def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

    def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None Process_Queue class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

     Process def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

     __init__ self.name = name self.name self name name self.r_time = r_time self.r_time self r_time r_time self.link = link self.link self link link self self name name r_time r_time link = None link None def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

     __init__ self.e_time = 0 self.e_time self e_time 0 self.q = q self.q self q q self.front = None self.front self front None self.rear  = None self.rear self rear None self self q q def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

     enqueue if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

     self.front == self.rear == None self.front == self.rear self.front self front self.rear self rear None self.front = self.rear = Process_Queue.Process(name, r_time) self.front self front Process_Queue.Process(name, r_time) Process_Queue.Process Process_Queue Process name r_time = self.rear = Process_Queue.Process(name, r_time) self.rear self rear Process_Queue.Process(name, r_time) new_process = Process_Queue.Process(name, r_time) new_process Process_Queue.Process(name, r_time) Process_Queue.Process Process_Queue Process name r_time self.rear.link = new_process self.rear.link self.rear self rear link new_process self.rear = new_process self.rear self rear new_process self self name name r_time r_time def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None dequeue if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
         self.front == self.rear == None self.front == self.rear self.front self front self.rear self rear None raise Exception("queue underflow") Exception("queue underflow") Exception "queue underflow" elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
         self.front.r_time > self.q self.front.r_time self.front self front r_time self.q self q self.enqueue(self.front.name, self.front.r_time - self.q) self.enqueue self enqueue self.front.name self.front self front name self.front.r_time - self.q self.front.r_time self.front self front r_time self.q self q self.front = self.front.link self.front self front self.front.link self.front self front link self.e_time += self.q self.e_time self e_time self.q self q p_name = self.front.name p_name self.front.name self.front self front name self.e_time += self.front.r_time self.e_time self e_time self.front.r_time self.front self front r_time print(p_name, self.e_time) print p_name self.e_time self e_time self.front = self.front.link self.front self front self.front.link self.front self front link if self.front == None:
            self.rear = None self.front == None self.front self front None self.rear = None self.rear self rear None self self n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q p_queue = Process_Queue(q) p_queue Process_Queue(q) Process_Queue q for i in range(n):
    p = input().split()
    p_queue.enqueue(p[0], int(p[1])) i range(n) range n p = input().split() p input().split() ().split () input split p_queue.enqueue(p[0], int(p[1])) p_queue.enqueue p_queue enqueue p[0] p 0 int(p[1]) int p[1] p 1 while not p_queue.front == p_queue.rear == None:
    p_queue.dequeue() not p_queue.front == p_queue.rear == None p_queue.front == p_queue.rear == None p_queue.front == p_queue.rear p_queue.front p_queue front p_queue.rear p_queue rear None p_queue.dequeue() p_queue.dequeue p_queue dequeue p_queue = Process_Queue(q) Process_Queue(q) p_queue n, q = map(int, input().split()) map(int, input().split()) n p = input().split() input().split() p class Process_Queue:
    class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

    def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

    def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

    def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None class Process_Queue:
    class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

    def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

    def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

    def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None Process_Queue q = map(int, input().split()) map(int, input().split()) q
class Process_Queue:
    class Process:
        def __init__(self, name, r_time, link = None):
            self.name = name
            self.r_time = r_time
            self.link = link

    def __init__(self, q):
        self.e_time = 0
        self.q = q
        self.front = None
        self.rear  = None

    def enqueue(self, name, r_time):
        if self.front == self.rear == None:
            self.front = self.rear = Process_Queue.Process(name, r_time)
        else:
            new_process = Process_Queue.Process(name, r_time)
            self.rear.link = new_process
            self.rear = new_process

    def dequeue(self):
        if self.front == self.rear == None:
            raise Exception("queue underflow")
        elif self.front.r_time > self.q:
            self.enqueue(self.front.name, self.front.r_time - self.q)
            self.front = self.front.link
            self.e_time += self.q
        else:
            p_name = self.front.name
            self.e_time += self.front.r_time
            print(p_name, self.e_time)
            self.front = self.front.link
        if self.front == None:
            self.rear = None

n, q = map(int, input().split())

p_queue = Process_Queue(q)

for i in range(n):
    p = input().split()
    p_queue.enqueue(p[0], int(p[1]))

while not p_queue.front == p_queue.rear == None:
    p_queue.dequeue()