class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1

if __name__ == '__main__':
    n, q = [int(x) for x in raw_input().split()]
    ps_list = []
    for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

    queue = Queue(ps_list)

    n_end_process = 0
    acc_time = 0
    while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h) class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1 Queue def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

     __init__ self._queue = l self._queue self _queue l self._n = len(l) self._n self _n len(l) len l self._head = 0 self._head self _head 0 self._tail = 0 self._tail self _tail 0 self self l l def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

     pop_left if self._head == self._n:
            self._head = 0
         self._head == self._n self._head self _head self._n self _n self._head = 0 self._head self _head 0 ret = self._queue[self._head][::] ret self._queue[self._head][::] self._queue[self._head] self._queue self _queue self._head self _head :: self._head += 1 self._head self _head 1 return ret ret self self def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1 push_right if self._tail == self._n:
            self._tail = 0
         self._tail == self._n self._tail self _tail self._n self _n self._tail = 0 self._tail self _tail 0 self._queue[self._tail] = x self._queue[self._tail] self._queue self _queue self._tail self _tail x self._tail += 1 self._tail self _tail 1 self self x x object if __name__ == '__main__':
    n, q = [int(x) for x in raw_input().split()]
    ps_list = []
    for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

    queue = Queue(ps_list)

    n_end_process = 0
    acc_time = 0
    while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h) __name__ == '__main__' __name__ '__main__' int(x) for x in raw_input().split() for x in raw_input().split() x raw_input().split() ().split () raw_input split for x in raw_input().split() int(x) int x n, q = [int(x) for x in raw_input().split()] n [int(x) for x in raw_input().split()] q ps_list = [] ps_list [] for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

     _ range(n) range n raw = raw_input().split() raw raw_input().split() ().split () raw_input split ps_list.append([raw[0], int(raw[1])]) ps_list.append ps_list append [raw[0], int(raw[1])] raw[0] raw 0 int(raw[1]) int raw[1] raw 1 queue = Queue(ps_list) queue Queue(ps_list) Queue ps_list n_end_process = 0 n_end_process 0 acc_time = 0 acc_time 0 while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h) n_end_process < n n_end_process n h = queue.pop_left() h queue.pop_left() queue.pop_left queue pop_left if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h) h[1] <= q h[1] h 1 q n_end_process += 1 n_end_process 1 acc_time += h[1] acc_time h[1] h 1 print "{} {}".format(h[0], acc_time) "{} {}".format "{} {}" format h[0] h 0 acc_time h[1] -= q h[1] h 1 q acc_time += q acc_time q queue.push_right(h) queue.push_right queue push_right h q = [int(x) for x in raw_input().split()] [int(x) for x in raw_input().split()] q class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1 class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1 Queue raw = raw_input().split() raw_input().split() raw ps_list = [] [] ps_list queue = Queue(ps_list) Queue(ps_list) queue n_end_process = 0 0 n_end_process h = queue.pop_left() queue.pop_left() h n, q = [int(x) for x in raw_input().split()] [int(x) for x in raw_input().split()] n acc_time += q q acc_time acc_time = 0 0 acc_time acc_time += h[1] h[1] acc_time n_end_process += 1 1 n_end_process
class Queue(object):

    def __init__(self, l):
        self._queue = l
        self._n = len(l)
        self._head = 0
        self._tail = 0

    def pop_left(self):
        if self._head == self._n:
            self._head = 0
        ret = self._queue[self._head][::]
        self._head += 1

        return ret

    def push_right(self, x):
        if self._tail == self._n:
            self._tail = 0
        self._queue[self._tail] = x
        self._tail += 1

if __name__ == '__main__':
    n, q = [int(x) for x in raw_input().split()]
    ps_list = []
    for _ in range(n):
        raw = raw_input().split()
        ps_list.append([raw[0], int(raw[1])])

    queue = Queue(ps_list)

    n_end_process = 0
    acc_time = 0
    while n_end_process < n:
        h = queue.pop_left()
        if h[1] <= q:
            n_end_process += 1
            acc_time += h[1]
            print "{} {}".format(h[0], acc_time)
        else:
            h[1] -= q
            acc_time += q
            queue.push_right(h)