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



que = []

for i in range(n):

    name, time = input().split()

    que.append([name, int(time)])



stime = 0

while que:

    job = que.pop(0)

    if job[1]<=q:

        stime += job[1]

        print(job[0], stime)

    else:

        stime += q

        job[1] -= q

        que.append(job)
import sys



class Queue:

    class Cell:

        def __init__(self, x, y = None):

            self.data = x

            self.next = y



    def __init__(self):

        self.size = 0

        self.rear = None



    def enqueue(self, x):

        if self.size == 0:

            self.rear = Queue.Cell(x)

            self.rear.next = self.rear

        else:

            new_cell = Queue.Cell(x, self.rear.__next__)

            self.rear.next = new_cell

            self.rear = new_cell

        self.size += 1



    def dequeue(self):

        if self.size == 0: raise IndexError

        front = self.rear.__next__

        self.rear.next = front.__next__

        self.size -= 1

        if self.size == 0: self.rear = None

        return front.data



    def isEmpty(self):

        return self.size == 0



def generator(n1, n2, step=1):

    n = n1

    while n<n2:

        yield n

        n+= step



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

 

A = Queue()

for i in generator(0,n):

    name, time = input().split()

    A.enqueue([name, int(time)])



stime = 0

while not A.isEmpty():

    job = A.dequeue()

    if q>=job[1]:

        stime += job[1]

        print(job[0], stime)

    else:

        stime += q

        job[1] -= q

        A.enqueue(job)
n, q = list(map(int, input().split()))
que = []
for i in range(n):
    name, time = input().split()
    que.append([name, int(time)])
stime = 0
while que:
    job = que.pop(0)
    if job[1] <= q:
        stime += job[1]
        print(job[0], stime)
    else:
        stime += q
        job[1] -= q
        que.append(job)

import sys


class Queue:
    class Cell:
        def __init__(self, x, y=None):
            self.data = x
            self.next = y

    def __init__(self):
        self.size = 0
        self.rear = None

    def enqueue(self, x):
        if self.size == 0:
            self.rear = Queue.Cell(x)
            self.rear.next = self.rear
        else:
            new_cell = Queue.Cell(x, self.rear.__next__)
            self.rear.next = new_cell
            self.rear = new_cell
        self.size += 1

    def dequeue(self):
        if self.size == 0:
            raise IndexError
        front = self.rear.__next__
        self.rear.next = front.__next__
        self.size -= 1
        if self.size == 0:
            self.rear = None
        return front.data

    def isEmpty(self):
        return self.size == 0


def generator(n1, n2, step=1):
    n = n1
    while n < n2:
        yield n
        n += step


n, q = list(map(int, input().split()))
A = Queue()
for i in generator(0, n):
    name, time = input().split()
    A.enqueue([name, int(time)])
stime = 0
while not A.isEmpty():
    job = A.dequeue()
    if q >= job[1]:
        stime += job[1]
        print(job[0], stime)
    else:
        stime += q
        job[1] -= q
        A.enqueue(job)

+import sys + + +class Queue: +    class Cell: +        def __init__(self, x, y=None): +            self.data = x +            self.next = y + +    def __init__(self): +        self.size = 0 +        self.rear = None + +    def enqueue(self, x): +        if self.size == 0: +            self.rear = Queue.Cell(x) +            self.rear.next = self.rear +        else: +            new_cell = Queue.Cell(x, self.rear.__next__) +            self.rear.next = new_cell +            self.rear = new_cell +        self.size += 1 + +    def dequeue(self): +        if self.size == 0: +            raise IndexError +        front = self.rear.__next__ +        self.rear.next = front.__next__ +        self.size -= 1 +        if self.size == 0: +            self.rear = None +        return front.data + +    def isEmpty(self): +        return self.size == 0 + + +def generator(n1, n2, step=1): +    n = n1 +    while n < n2: +        yield n +        n += step + + -que = [] -for i in range(n): +A = Queue() +for i in generator(0, n): -    que.append([name, int(time)]) +    A.enqueue([name, int(time)]) -while que: -    job = que.pop(0) -    if job[1] <= q: +while not A.isEmpty(): +    job = A.dequeue() +    if q >= job[1]: -        que.append(job) +        A.enqueue(job)