class Queue:

    def __init__(self,values):

        self.values = values



    def empty(self):

        if len(self.values) == 0:

            return True

        else:

            return False



    def enqueue(self,v):

        self.values.append(v)



    def dequeue(self):

        if len(self.values) <= 0:

            raise

        else:

            v = self.values[0]

            del self.values[0]

            return v



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

processes = []

for i in range(n):

    n,t = input().split(' ')

    processes.append((n,int(t)))



queue = Queue(processes)



clock = 0

done = []

while not queue.empty():

    p = queue.dequeue()

    n = p[0]

    t = p[1]

    if t <= q:

        clock+=t

        done.append((n,clock))

    else:

        queue.enqueue((n,t-q))

        clock+=q



for p in done:

    print(p[0],p[1])
class Queue:

    def __init__(self,l):

        self.values = []

        self.l = l

        for _ in range(l):

            self.values.append(None)

        self.head = 0

        self.tail = 0

    def inc(self,n):

        if n+1 >= self.l:

            return 0

        else:

            return n+1

    def enqueue(self,v):

        if self.inc(self.head) == self.tail:

            print('overflow')

            exit()

        self.values[self.head] = v

        self.head = self.inc(self.head)

    def dequeue(self):

        if self.head == self.tail:

            print('underflow')

            exit()

        v = self.values[self.tail]

        self.tail = self.inc(self.tail)

        return v

    def size(self):

        if self.head >= self.tail:

            return self.head-self.tail

        else:

            self.head + (self.l-self.tail)



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

queue = Queue(200000)

for _ in range(n):

    n,t = input().split(' ')

    t = int(t)

    queue.enqueue((n,t))



c = 0

while queue.size()>0:

    n,t = queue.dequeue()

    if t <= q:

        c += t

        print(n,c)

    else:

        queue.enqueue((n,t-q))

        c += q
class Queue:
    def __init__(self, values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

    def enqueue(self, v):
        self.values.append(v)

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v


n, q = list(map(int, input().split(" ")))
processes = []
for i in range(n):
    n, t = input().split(" ")
    processes.append((n, int(t)))
queue = Queue(processes)
clock = 0
done = []
while not queue.empty():
    p = queue.dequeue()
    n = p[0]
    t = p[1]
    if t <= q:
        clock += t
        done.append((n, clock))
    else:
        queue.enqueue((n, t - q))
        clock += q
for p in done:
    print(p[0], p[1])

class Queue:
    def __init__(self, l):
        self.values = []
        self.l = l
        for _ in range(l):
            self.values.append(None)
        self.head = 0
        self.tail = 0

    def inc(self, n):
        if n + 1 >= self.l:
            return 0
        else:
            return n + 1

    def enqueue(self, v):
        if self.inc(self.head) == self.tail:
            print("overflow")
            exit()
        self.values[self.head] = v
        self.head = self.inc(self.head)

    def dequeue(self):
        if self.head == self.tail:
            print("underflow")
            exit()
        v = self.values[self.tail]
        self.tail = self.inc(self.tail)
        return v

    def size(self):
        if self.head >= self.tail:
            return self.head - self.tail
        else:
            self.head + (self.l - self.tail)


n, q = list(map(int, input().split(" ")))
queue = Queue(200000)
for _ in range(n):
    n, t = input().split(" ")
    t = int(t)
    queue.enqueue((n, t))
c = 0
while queue.size() > 0:
    n, t = queue.dequeue()
    if t <= q:
        c += t
        print(n, c)
    else:
        queue.enqueue((n, t - q))
        c += q

-    def __init__(self, values): -        self.values = values +    def __init__(self, l): +        self.values = [] +        self.l = l +        for _ in range(l): +            self.values.append(None) +        self.head = 0 +        self.tail = 0 -    def empty(self): -        if len(self.values) == 0: -            return True +    def inc(self, n): +        if n + 1 >= self.l: +            return 0 -            return False +            return n + 1 -        self.values.append(v) +        if self.inc(self.head) == self.tail: +            print("overflow") +            exit() +        self.values[self.head] = v +        self.head = self.inc(self.head) -        if len(self.values) <= 0: -            raise +        if self.head == self.tail: +            print("underflow") +            exit() +        v = self.values[self.tail] +        self.tail = self.inc(self.tail) +        return v + +    def size(self): +        if self.head >= self.tail: +            return self.head - self.tail -            v = self.values[0] -            del self.values[0] -            return v +            self.head + (self.l - self.tail) -processes = [] -for i in range(n): +queue = Queue(200000) +for _ in range(n): -    processes.append((n, int(t))) -queue = Queue(processes) -clock = 0 -done = [] -while not queue.empty(): -    p = queue.dequeue() -    n = p[0] -    t = p[1] +    t = int(t) +    queue.enqueue((n, t)) +c = 0 +while queue.size() > 0: +    n, t = queue.dequeue() -        clock += t -        done.append((n, clock)) +        c += t +        print(n, c) -        clock += q -for p in done: -    print(p[0], p[1]) +        c += q