#!/usr/bin/env python

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





class Queue:

    def __init__(self):

        self.l = []



    def enqueue(self, x):

        self.l.append(x)



    def dequeue(self):

        x = self.l[0]

        del self.l[0]

        return x



    def is_empty(self):

        return len(self.l) == 0





class Process:

    def __init__(self, name, time):

        self.name = name

        self.time = time





if __name__ == '__main__':

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

    Q = Queue()

    i = 0

    while i != n:

        tmp = input().split()

        Q.enqueue(Process(tmp[0], int(tmp[1])))

        i += 1

    cnt = 0

    while not Q.is_empty():

        p = Q.dequeue()

        if p.time > q:

            p.time -= q

            cnt += q

            Q.enqueue(p)

        else:

            cnt += p.time

            print(p.name, cnt)



class Queue:

    def __init__(self, n):

        self.A = [0 for i in range(n)]

        self.head = 0

        self.tail = 0

        self.len = n



    def is_empty(self):

        return self.head == self.tail



    def is_full(self):

        return (self.tail + 1) % self.len == self.head



    def enqueue(self, x):

        if not self.is_full():

            self.A[self.tail] = x

            self.tail += 1

            if self.tail == self.len:

                self.tail = 0



    def dequeue(self):

        if not self.is_empty():

            x = self.A[self.head]

            self.head += 1

            if self.head == self.len:

                self.head = 0

            return x





class Task:

    def __init__(self, name, time):

        self.name = name

        self.time = time





if __name__ == '__main__':

    Q = Queue(100005)

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

    for i in range(n):

        l = input().split()

        t = Task(l[0], int(l[1]))

        Q.enqueue(t)



    cnt = 0

    while not Q.is_empty():

        t = Q.dequeue()

        if t.time > q:

            cnt += q

            t.time -= q

            Q.enqueue(t)

        else:

            cnt += t.time

            print(t.name, cnt)



    pass

#!/usr/bin/env python
# -*- coding: utf-8 -*-
class Queue:
    def __init__(self):
        self.l = []

    def enqueue(self, x):
        self.l.append(x)

    def dequeue(self):
        x = self.l[0]
        del self.l[0]
        return x

    def is_empty(self):
        return len(self.l) == 0


class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time


if __name__ == "__main__":
    n, q = list(map(int, input().split()))
    Q = Queue()
    i = 0
    while i != n:
        tmp = input().split()
        Q.enqueue(Process(tmp[0], int(tmp[1])))
        i += 1
    cnt = 0
    while not Q.is_empty():
        p = Q.dequeue()
        if p.time > q:
            p.time -= q
            cnt += q
            Q.enqueue(p)
        else:
            cnt += p.time
            print(p.name, cnt)

class Queue:
    def __init__(self, n):
        self.A = [0 for i in range(n)]
        self.head = 0
        self.tail = 0
        self.len = n

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

    def is_full(self):
        return (self.tail + 1) % self.len == self.head

    def enqueue(self, x):
        if not self.is_full():
            self.A[self.tail] = x
            self.tail += 1
            if self.tail == self.len:
                self.tail = 0

    def dequeue(self):
        if not self.is_empty():
            x = self.A[self.head]
            self.head += 1
            if self.head == self.len:
                self.head = 0
            return x


class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time


if __name__ == "__main__":
    Q = Queue(100005)
    n, q = list(map(int, input().split()))
    for i in range(n):
        l = input().split()
        t = Task(l[0], int(l[1]))
        Q.enqueue(t)
    cnt = 0
    while not Q.is_empty():
        t = Q.dequeue()
        if t.time > q:
            cnt += q
            t.time -= q
            Q.enqueue(t)
        else:
            cnt += t.time
            print(t.name, cnt)
    pass

-#!/usr/bin/env python -# -*- coding: utf-8 -*- -    def __init__(self): -        self.l = [] +    def __init__(self, n): +        self.A = [0 for i in range(n)] +        self.head = 0 +        self.tail = 0 +        self.len = n + +    def is_empty(self): +        return self.head == self.tail + +    def is_full(self): +        return (self.tail + 1) % self.len == self.head -        self.l.append(x) +        if not self.is_full(): +            self.A[self.tail] = x +            self.tail += 1 +            if self.tail == self.len: +                self.tail = 0 -        x = self.l[0] -        del self.l[0] -        return x - -    def is_empty(self): -        return len(self.l) == 0 +        if not self.is_empty(): +            x = self.A[self.head] +            self.head += 1 +            if self.head == self.len: +                self.head = 0 +            return x -class Process: +class Task: +    Q = Queue(100005) -    Q = Queue() -    i = 0 -    while i != n: -        tmp = input().split() -        Q.enqueue(Process(tmp[0], int(tmp[1]))) -        i += 1 +    for i in range(n): +        l = input().split() +        t = Task(l[0], int(l[1])) +        Q.enqueue(t) -        p = Q.dequeue() -        if p.time > q: -            p.time -= q +        t = Q.dequeue() +        if t.time > q: -            Q.enqueue(p) +            t.time -= q +            Q.enqueue(t) -            cnt += p.time -            print(p.name, cnt) +            cnt += t.time +            print(t.name, cnt) +    pass