class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1

current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time) class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False MyQueue """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """ def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

     __init__ """Constructor
        """ self.length = 100010 self.length self length 100010 self.queue = [] self.queue self queue [] counter = 0 counter 0 while counter < self.length:
            self.queue.append(Process())
            counter += 1
         counter < self.length counter self.length self length self.queue.append(Process()) self.queue.append self.queue self queue append Process() Process counter += 1 counter 1 self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self self def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

     enqueue """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """ if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

     self.is_full() self.is_full self is_full print("[ERROR] Queue Overflow") print "[ERROR] Queue Overflow" self.queue[self.tail % self.length].name = name self.queue[self.tail % self.length].name self.queue[self.tail % self.length] self.queue self queue self.tail % self.length self.tail self tail self.length self length name name self.queue[self.tail % self.length].time = time self.queue[self.tail % self.length].time self.queue[self.tail % self.length] self.queue self queue self.tail % self.length self.tail self tail self.length self length time time self.tail += 1 self.tail self tail 1 self self name name time time def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

     dequeue """dequeue method

        Returns:
            None
        """ if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

     self.is_empty() self.is_empty self is_empty print("[ERROR] Queue Underflow") print "[ERROR] Queue Underflow" self.queue[self.head % self.length].name = "" self.queue[self.head % self.length].name self.queue[self.head % self.length] self.queue self queue self.head % self.length self.head self head self.length self length name "" self.queue[self.head % self.length].time = 0 self.queue[self.head % self.length].time self.queue[self.head % self.length] self.queue self queue self.head % self.length self.head self head self.length self length time 0 self.head += 1 self.head self head 1 self self def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

     is_empty """check queue is empty or not

        Returns:
            Bool
        """ if self.head == self.tail:
            return True
        else:
            return False

     self.head == self.tail self.head self head self.tail self tail return True True return False False self self def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False is_full """chech whether queue is full or not""" if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False self.tail - self.head >= len(self.queue) self.tail - self.head self.tail self tail self.head self head len(self.queue) len self.queue self queue return True True return False False self self object class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time Process """process class
    """ def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

     __init__ """constructor
        Args:
            name: name
            time: time
        """ self.name = name self.name self name name self.time = time self.time self time time self self name="" name "" time=0 time 0 def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time forward_time """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """ self.time -= time self.time self time time return self.time self.time self time self self time time object def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time time_forward """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """ value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval) value my_queue.queue[my_queue.head % my_queue.length].forward_time(interval) my_queue.queue[my_queue.head % my_queue.length].forward_time my_queue.queue[my_queue.head % my_queue.length] my_queue.queue my_queue queue my_queue.head % my_queue.length my_queue.head my_queue head my_queue.length my_queue length forward_time interval if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time value < 0 value 0 current_time += (interval + value) current_time interval + value interval value print my_queue.queue[my_queue.head % my_queue.length].name my_queue.queue[my_queue.head % my_queue.length] my_queue.queue my_queue queue my_queue.head % my_queue.length my_queue.head my_queue head my_queue.length my_queue length name current_time my_queue.dequeue() my_queue.dequeue my_queue dequeue return current_time current_time elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

     value == 0 value 0 current_time += interval current_time interval print my_queue.queue[my_queue.head % my_queue.length].name my_queue.queue[my_queue.head % my_queue.length] my_queue.queue my_queue queue my_queue.head % my_queue.length my_queue.head my_queue head my_queue.length my_queue length name current_time my_queue.dequeue() my_queue.dequeue my_queue dequeue return current_time current_time elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time value > 0 value 0 current_time += interval current_time interval copied_process = my_queue.queue[my_queue.head % my_queue.length] copied_process my_queue.queue[my_queue.head % my_queue.length] my_queue.queue my_queue queue my_queue.head % my_queue.length my_queue.head my_queue head my_queue.length my_queue length name, time = copied_process.name, copied_process.time name copied_process.name copied_process name time copied_process.time copied_process time my_queue.dequeue() my_queue.dequeue my_queue dequeue my_queue.enqueue(name, time) my_queue.enqueue my_queue enqueue name time return current_time current_time my_queue my_queue interval interval current_time current_time my_queue = MyQueue() my_queue MyQueue() MyQueue int(x) for x in raw_input().split() for x in raw_input().split() x raw_input().split() ().split () raw_input split for x in raw_input().split() int(x) int x n, q = [int(x) for x in raw_input().split()] n [int(x) for x in raw_input().split()] q counter = 0 counter 0 while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1 counter < n counter n name, time = raw_input().split() name raw_input().split() ().split () raw_input split time my_queue.enqueue(name, int(time)) my_queue.enqueue my_queue enqueue name int(time) int time counter += 1 counter 1 current_time = 0 current_time 0 while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time) not my_queue.is_empty() my_queue.is_empty() my_queue.is_empty my_queue is_empty current_time = time_forward(my_queue, q, current_time) current_time time_forward(my_queue, q, current_time) time_forward my_queue q current_time n, q = [int(x) for x in raw_input().split()] [int(x) for x in raw_input().split()] n current_time = 0 0 current_time class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False MyQueue def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time time_forward time = raw_input().split() raw_input().split() time counter = 0 0 counter name, time = raw_input().split() raw_input().split() name my_queue = MyQueue() MyQueue() my_queue current_time = time_forward(my_queue, q, current_time) time_forward(my_queue, q, current_time) current_time q = [int(x) for x in raw_input().split()] [int(x) for x in raw_input().split()] q counter += 1 1 counter class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time Process
class MyQueue(object):
    """
    My Queue class

    Attributes:
        queue: queue
        head
        tail
    """

    def __init__(self):
        """Constructor
        """
        self.length = 100010
        self.queue = []
        counter = 0
        while counter < self.length:
            self.queue.append(Process())
            counter += 1
        self.head = 0
        self.tail = 0

    def enqueue(self, name, time):
        """enqueue method

        Args:
            name: enqueued process name
            time: enqueued process time

        Returns:
            None
        """
        if self.is_full():
            print("[ERROR] Queue Overflow")
        else:
            self.queue[self.tail % self.length].name = name
            self.queue[self.tail % self.length].time = time
            self.tail += 1

    def dequeue(self):
        """dequeue method

        Returns:
            None
        """
        if self.is_empty():
            print("[ERROR] Queue Underflow")
        else:
            self.queue[self.head % self.length].name = ""
            self.queue[self.head % self.length].time = 0
            self.head += 1

    def is_empty(self):
        """check queue is empty or not

        Returns:
            Bool
        """
        if self.head == self.tail:
            return True
        else:
            return False

    def is_full(self):
        """chech whether queue is full or not"""
        if self.tail - self.head >= len(self.queue):
            return True
        else:
            return False


class Process(object):
    """process class
    """

    def __init__(self, name="", time=0):
        """constructor
        Args:
            name: name
            time: time
        """
        self.name = name
        self.time = time

    def forward_time(self, time):
        """time forward method

        Args:
            time: forward time interval

        Returns:
            remain time

        """
        self.time -= time
        return self.time


def time_forward(my_queue, interval, current_time):
    """

    Args:
        my_queue: queue
        interval: time step interval
        current_time: current time
    """

    value = my_queue.queue[my_queue.head % my_queue.length].forward_time(interval)
    if value < 0:
        current_time += (interval + value)
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value == 0:
        current_time += interval
        print my_queue.queue[my_queue.head % my_queue.length].name, current_time
        my_queue.dequeue()
        return current_time

    elif value > 0:
        current_time += interval
        copied_process = my_queue.queue[my_queue.head % my_queue.length]
        name, time = copied_process.name, copied_process.time
        my_queue.dequeue()
        my_queue.enqueue(name, time)
        return current_time


my_queue = MyQueue()
n, q = [int(x) for x in raw_input().split()]
counter = 0
while counter < n:
    name, time = raw_input().split()
    my_queue.enqueue(name, int(time))
    counter += 1

current_time = 0
while not my_queue.is_empty():
    current_time = time_forward(my_queue, q, current_time)