# -*- coding: utf-8 -*-

class RingBuffer(list):
    def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

    def isEmpty(self):
        return self.head == self.tail
    
    def enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x



if __name__ == '__main__':

    n, q = [int(c) for c in input().split(" ")]
    P = RingBuffer(n+1)
    
    for i in range(n):
        P_name, P_time = input().split(" ")
        P.enque([P_name, int(P_time)])

    time = 0
    while not P.isEmpty():
        P_name, P_time = P.deque()
        
        if P_time > q:
            time = time + q
            P_time = P_time - q
            P.enque([P_name, P_time])
        else:
            time = time + P_time
            print(P_name, time)

 class RingBuffer(list):
    def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

    def isEmpty(self):
        return self.head == self.tail
    
    def enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x RingBuffer def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

     __init__ list.__init__(self) list.__init__ list __init__ self self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self.MAX = MAX self.MAX self MAX MAX self[:] = [None]*MAX self[:] self : [None]*MAX [None] None MAX self self MAX MAX 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 enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

     enque self[self.tail] = x self[self.tail] self self.tail self tail x if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

     self.tail + 1 == self.MAX self.tail + 1 self.tail self tail 1 self.MAX self MAX self.tail = 0 self.tail self tail 0 self.tail += 1 self.tail self tail 1 self self x x def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x deque x = self[self.head] x self[self.head] self self.head self head if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
         self.head + 1 == self.MAX self.head + 1 self.head self head 1 self.MAX self MAX self.head = 0 self.head self head 0 self.head += 1 self.head self head 1 return x x self self list if __name__ == '__main__':

    n, q = [int(c) for c in input().split(" ")]
    P = RingBuffer(n+1)
    
    for i in range(n):
        P_name, P_time = input().split(" ")
        P.enque([P_name, int(P_time)])

    time = 0
    while not P.isEmpty():
        P_name, P_time = P.deque()
        
        if P_time > q:
            time = time + q
            P_time = P_time - q
            P.enque([P_name, P_time])
        else:
            time = time + P_time
            print(P_name, time) __name__ == '__main__' __name__ '__main__' int(c) for c in input().split(" ") for c in input().split(" ") c input().split(" ") ().split () input split " " for c in input().split(" ") int(c) int c n, q = [int(c) for c in input().split(" ")] n [int(c) for c in input().split(" ")] q P = RingBuffer(n+1) P RingBuffer(n+1) RingBuffer n+1 n 1 for i in range(n):
        P_name, P_time = input().split(" ")
        P.enque([P_name, int(P_time)])

     i range(n) range n P_name, P_time = input().split(" ") P_name input().split(" ") ().split () input split " " P_time P.enque([P_name, int(P_time)]) P.enque P enque [P_name, int(P_time)] P_name int(P_time) int P_time time = 0 time 0 while not P.isEmpty():
        P_name, P_time = P.deque()
        
        if P_time > q:
            time = time + q
            P_time = P_time - q
            P.enque([P_name, P_time])
        else:
            time = time + P_time
            print(P_name, time) not P.isEmpty() P.isEmpty() P.isEmpty P isEmpty P_name, P_time = P.deque() P_name P.deque() P.deque P deque P_time if P_time > q:
            time = time + q
            P_time = P_time - q
            P.enque([P_name, P_time])
        else:
            time = time + P_time
            print(P_name, time) P_time > q P_time q time = time + q time time + q time q P_time = P_time - q P_time P_time - q P_time q P.enque([P_name, P_time]) P.enque P enque [P_name, P_time] P_name P_time time = time + P_time time time + P_time time P_time print(P_name, time) print P_name time P_time = P.deque() P.deque() P_time P_time = input().split(" ") input().split(" ") P_time P_name, P_time = P.deque() P.deque() P_name P_time = P_time - q P_time - q P_time class RingBuffer(list):
    def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

    def isEmpty(self):
        return self.head == self.tail
    
    def enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x class RingBuffer(list):
    def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

    def isEmpty(self):
        return self.head == self.tail
    
    def enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x RingBuffer P = RingBuffer(n+1) RingBuffer(n+1) P time = time + P_time time + P_time time n, q = [int(c) for c in input().split(" ")] [int(c) for c in input().split(" ")] n P_name, P_time = input().split(" ") input().split(" ") P_name time = 0 0 time q = [int(c) for c in input().split(" ")] [int(c) for c in input().split(" ")] q time = time + q time + q time
# -*- coding: utf-8 -*-

class RingBuffer(list):
    def __init__(self, MAX):
        list.__init__(self)
        self.head = 0
        self.tail = 0
        self.MAX = MAX
        self[:] = [None]*MAX

    def isEmpty(self):
        return self.head == self.tail
    
    def enque(self,x):
        self[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def deque(self):
        x = self[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x



if __name__ == '__main__':

    n, q = [int(c) for c in input().split(" ")]
    P = RingBuffer(n+1)
    
    for i in range(n):
        P_name, P_time = input().split(" ")
        P.enque([P_name, int(P_time)])

    time = 0
    while not P.isEmpty():
        P_name, P_time = P.deque()
        
        if P_time > q:
            time = time + q
            P_time = P_time - q
            P.enque([P_name, P_time])
        else:
            time = time + P_time
            print(P_name, time)


