class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt


class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

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

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

s = MyQueue()
result = list()
process = 0

for i in range(n):
    name, time = map(str, input().split())
    s.enqueue([name, int(time)])

while not s.is_empty():

    e = s.dequeue()
    diff = e[1] - q
    if diff <= 0:
        process += e[1]
        result.append([e[0], process])
    else:
        process += q
        s.enqueue([e[0], diff])
for i in result:
    print(i[0], i[1]) class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt Node elm = None elm None nxt = None nxt None def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt __init__ self.elm = elm self.elm self elm elm self.nxt = nxt self.nxt self nxt nxt self self elm elm nxt nxt class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

    def is_empty(self):
        return self.size == 0 MyQueue head = tail = None head None = tail = None tail None size = 0 size 0 def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

     enqueue if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
         self.is_empty() self.is_empty self is_empty self.head = self.tail = Node(x, None) self.head self head Node(x, None) Node x None = self.tail = Node(x, None) self.tail self tail Node(x, None) self.tail.nxt = Node(x, None) self.tail.nxt self.tail self tail nxt Node(x, None) Node x None self.tail = self.tail.nxt self.tail self tail self.tail.nxt self.tail self tail nxt self.size += 1 self.size self size 1 self self x x def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

     dequeue n = self.head n self.head self head if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
         not self.is_empty() self.is_empty() self.is_empty self is_empty self.head = self.head.nxt self.head self head self.head.nxt self.head self head nxt self.size -= 1 self.size self size 1 return n.elm n.elm n elm self self def is_empty(self):
        return self.size == 0 is_empty return self.size == 0 self.size == 0 self.size self size 0 self self n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q s = MyQueue() s MyQueue() MyQueue result = list() result list() list process = 0 process 0 for i in range(n):
    name, time = map(str, input().split())
    s.enqueue([name, int(time)]) i range(n) range n name, time = map(str, input().split()) name map(str, input().split()) map str input().split() ().split () input split time s.enqueue([name, int(time)]) s.enqueue s enqueue [name, int(time)] name int(time) int time while not s.is_empty():

    e = s.dequeue()
    diff = e[1] - q
    if diff <= 0:
        process += e[1]
        result.append([e[0], process])
    else:
        process += q
        s.enqueue([e[0], diff]) not s.is_empty() s.is_empty() s.is_empty s is_empty e = s.dequeue() e s.dequeue() s.dequeue s dequeue diff = e[1] - q diff e[1] - q e[1] e 1 q if diff <= 0:
        process += e[1]
        result.append([e[0], process])
    else:
        process += q
        s.enqueue([e[0], diff]) diff <= 0 diff 0 process += e[1] process e[1] e 1 result.append([e[0], process]) result.append result append [e[0], process] e[0] e 0 process process += q process q s.enqueue([e[0], diff]) s.enqueue s enqueue [e[0], diff] e[0] e 0 diff for i in result:
    print(i[0], i[1]) i result print(i[0], i[1]) print i[0] i 0 i[1] i 1 name, time = map(str, input().split()) map(str, input().split()) name result = list() list() result e = s.dequeue() s.dequeue() e process = 0 0 process class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt Node n, q = map(int, input().split()) map(int, input().split()) n s = MyQueue() MyQueue() s process += e[1] e[1] process process += q q process class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

    def is_empty(self):
        return self.size == 0 class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

    def is_empty(self):
        return self.size == 0 MyQueue diff = e[1] - q e[1] - q diff q = map(int, input().split()) map(int, input().split()) q time = map(str, input().split()) map(str, input().split()) time
class Node:
    elm = None
    nxt = None

    def __init__(self, elm, nxt):
        self.elm = elm
        self.nxt = nxt


class MyQueue:
    head = tail = None
    size = 0

    def enqueue(self, x):
        if self.is_empty():
            self.head = self.tail = Node(x, None)
        else:
            self.tail.nxt = Node(x, None)
            self.tail = self.tail.nxt
        self.size += 1

    def dequeue(self):
        n = self.head
        if not self.is_empty():
            self.head = self.head.nxt
            self.size -= 1
        return n.elm

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

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

s = MyQueue()
result = list()
process = 0

for i in range(n):
    name, time = map(str, input().split())
    s.enqueue([name, int(time)])

while not s.is_empty():

    e = s.dequeue()
    diff = e[1] - q
    if diff <= 0:
        process += e[1]
        result.append([e[0], process])
    else:
        process += q
        s.enqueue([e[0], diff])
for i in result:
    print(i[0], i[1])