class Queue:
    def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

    def initialize(self):
        self.head = 0
        self.tail = 0

    def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

    def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

    def isEmpty(self):
        return self.head == self.tail

if __name__ == '__main__':

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

    Q = Queue(n+10)

    for i in range(n):
        name, time = input().split(' ')
        time = int(time)
        Q.enqueue([name,time])

    c = 0

    while Q.head != Q.tail:
        proc = Q.dequeue()
        if proc[1]-q > 0:
            Q.enqueue([proc[0],proc[1]-q])
            c += q
        else:
            c += proc[1]
            print(proc[0],c) class Queue:
    def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

    def initialize(self):
        self.head = 0
        self.tail = 0

    def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

    def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

    def isEmpty(self):
        return self.head == self.tail Queue def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

     __init__ self.Q = [None]*limit self.Q self Q [None]*limit [None] None limit self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self.limit = limit self.limit self limit limit self self limit limit def initialize(self):
        self.head = 0
        self.tail = 0

     initialize self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self self def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

     enqueue self.Q[self.tail] = x self.Q[self.tail] self.Q self Q self.tail self tail x self.tail = (self.tail+1) % self.limit self.tail self tail (self.tail+1) % self.limit self.tail+1 self.tail self tail 1 self.limit self limit self self x x def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

     dequeue if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

     self.isEmpty() self.isEmpty self isEmpty print('error') print 'error' self.head = (self.head+1) % self.limit self.head self head (self.head+1) % self.limit self.head+1 self.head self head 1 self.limit self limit return self.Q[self.head-1] self.Q[self.head-1] self.Q self Q self.head-1 self.head self head 1 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 if __name__ == '__main__':

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

    Q = Queue(n+10)

    for i in range(n):
        name, time = input().split(' ')
        time = int(time)
        Q.enqueue([name,time])

    c = 0

    while Q.head != Q.tail:
        proc = Q.dequeue()
        if proc[1]-q > 0:
            Q.enqueue([proc[0],proc[1]-q])
            c += q
        else:
            c += proc[1]
            print(proc[0],c) __name__ == '__main__' __name__ '__main__' n,q = map(int, input().split(' ')) n map(int, input().split(' ')) map int input().split(' ') ().split () input split ' ' q Q = Queue(n+10) Q Queue(n+10) Queue n+10 n 10 for i in range(n):
        name, time = input().split(' ')
        time = int(time)
        Q.enqueue([name,time])

     i range(n) range n name, time = input().split(' ') name input().split(' ') ().split () input split ' ' time time = int(time) time int(time) int time Q.enqueue([name,time]) Q.enqueue Q enqueue [name,time] name time c = 0 c 0 while Q.head != Q.tail:
        proc = Q.dequeue()
        if proc[1]-q > 0:
            Q.enqueue([proc[0],proc[1]-q])
            c += q
        else:
            c += proc[1]
            print(proc[0],c) Q.head != Q.tail Q.head Q head Q.tail Q tail proc = Q.dequeue() proc Q.dequeue() Q.dequeue Q dequeue if proc[1]-q > 0:
            Q.enqueue([proc[0],proc[1]-q])
            c += q
        else:
            c += proc[1]
            print(proc[0],c) proc[1]-q > 0 proc[1]-q proc[1] proc 1 q 0 Q.enqueue([proc[0],proc[1]-q]) Q.enqueue Q enqueue [proc[0],proc[1]-q] proc[0] proc 0 proc[1]-q proc[1] proc 1 q c += q c q c += proc[1] c proc[1] proc 1 print(proc[0],c) print proc[0] proc 0 c class Queue:
    def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

    def initialize(self):
        self.head = 0
        self.tail = 0

    def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

    def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

    def isEmpty(self):
        return self.head == self.tail class Queue:
    def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

    def initialize(self):
        self.head = 0
        self.tail = 0

    def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

    def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

    def isEmpty(self):
        return self.head == self.tail Queue n,q = map(int, input().split(' ')) map(int, input().split(' ')) n proc = Q.dequeue() Q.dequeue() proc q = map(int, input().split(' ')) map(int, input().split(' ')) q c += q q c c += proc[1] proc[1] c name, time = input().split(' ') input().split(' ') name Q = Queue(n+10) Queue(n+10) Q time = int(time) int(time) time time = input().split(' ') input().split(' ') time c = 0 0 c
class Queue:
    def __init__(self, limit):
        self.Q = [None]*limit
        self.head = 0
        self.tail = 0
        self.limit = limit

    def initialize(self):
        self.head = 0
        self.tail = 0

    def enqueue(self,x):
        self.Q[self.tail] = x
        self.tail = (self.tail+1) % self.limit

    def dequeue(self):
        if self.isEmpty():
            print('error')
        else:
            self.head = (self.head+1) % self.limit
            return self.Q[self.head-1]

    def isEmpty(self):
        return self.head == self.tail

if __name__ == '__main__':

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

    Q = Queue(n+10)

    for i in range(n):
        name, time = input().split(' ')
        time = int(time)
        Q.enqueue([name,time])

    c = 0

    while Q.head != Q.tail:
        proc = Q.dequeue()
        if proc[1]-q > 0:
            Q.enqueue([proc[0],proc[1]-q])
            c += q
        else:
            c += proc[1]
            print(proc[0],c)