class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

    def isFull(self):
        return self.head == (self.tail + 1) % self.S


def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a)

if __name__ == "__main__":
    main() class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

    def isFull(self):
        return self.head == (self.tail + 1) % self.S My_Queue def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

     __init__ self.S = S self.S self S S 0 for i in range(S) for i in range(S) i range(S) range S for i in range(S) 0 self.q = [0 for i in range(S)] self.q self q [0 for i in range(S)] self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self self S S def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

     enqueue if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

     self.isFull() self.isFull self isFull print('overflow') print 'overflow' raise self.q[self.tail] = x self.q[self.tail] self.q self q self.tail self tail x if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

     self.tail + 1 == self.S self.tail + 1 self.tail self tail 1 self.S self S self.tail = 0 self.tail self tail 0 self.tail += 1 self.tail self tail 1 self self x x def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

     dequeue if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

     self.isEmpty() self.isEmpty self isEmpty print('underflow') print 'underflow' raise x = self.q[self.head] x self.q[self.head] self.q self q self.head self head self.q[self.head] = 0 self.q[self.head] self.q self q self.head self head 0 if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
             self.head + 1 == self.S self.head + 1 self.head self head 1 self.S self S self.head = 0 self.head self head 0 self.head += 1 self.head self head 1 return x x 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 def isFull(self):
        return self.head == (self.tail + 1) % self.S isFull return self.head == (self.tail + 1) % self.S self.head == (self.tail + 1) % self.S self.head self head (self.tail + 1) % self.S self.tail + 1 self.tail self tail 1 self.S self S self self def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a) main n, qms = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split qms elapsed_time = 0 elapsed_time 0 q = My_Queue(n + 1) q My_Queue(n + 1) My_Queue n + 1 n 1 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 while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a) q.head != q.tail q.head q head q.tail q tail a = q.dequeue() a q.dequeue() q.dequeue q dequeue if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a) a[1] <= qms a[1] a 1 qms elapsed_time += a[1] elapsed_time a[1] a 1 print(a[0], elapsed_time) print a[0] a 0 elapsed_time a[1] -= qms a[1] a 1 qms elapsed_time += qms elapsed_time qms q.enqueue(a) q.enqueue q enqueue a if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a) def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a) main class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

    def isFull(self):
        return self.head == (self.tail + 1) % self.S class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

    def isFull(self):
        return self.head == (self.tail + 1) % self.S My_Queue
class My_Queue:

    def __init__(self, S):
        self.S = S
        self.q = [0 for i in range(S)]
        self.head = 0
        self.tail = 0

    def enqueue(self, x):
        if self.isFull():
            print('overflow')
            raise
        else:
            self.q[self.tail] = x

            if self.tail + 1 == self.S:
                self.tail = 0
            else:
                self.tail += 1

    def dequeue(self):
        if self.isEmpty():
            print('underflow')
            raise
        else:
            x = self.q[self.head]
            self.q[self.head] = 0

            if self.head + 1 == self.S:
                self.head = 0
            else:
                self.head += 1
            return x

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

    def isFull(self):
        return self.head == (self.tail + 1) % self.S


def main():
    n, qms = map(int, input().split())
    elapsed_time = 0
    q = My_Queue(n + 1)
    for i in range(n):
        name, time = input().split()
        time = int(time)

        q.enqueue([name, time])

    while(q.head != q.tail):
        a = q.dequeue()
        if a[1] <= qms:
            elapsed_time += a[1]
            print(a[0], elapsed_time)
        else:
            a[1] -= qms
            elapsed_time += qms
            q.enqueue(a)

if __name__ == "__main__":
    main()