class Queue:
    def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

    def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

    def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

    def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret

n, q = map(int, raw_input().split(' '))
queue = Queue(n+1)
for _ in range(n):
    name, time = raw_input().split(' ')
    time = int(time)
    queue.enqueue((name, time))

completed = []
cur = 0
while len(completed) < n:
    name, time = queue.dequeue()
    res = time-q
    if res <= 0:
        cur += time
        completed.append((name, cur))
    else:
        cur += q
        queue.enqueue((name, res))

for name, time in completed:
    print name, time class Queue:
    def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

    def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

    def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

    def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret Queue def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

     __init__ self.values = [None]*n self.values self values [None]*n [None] None n self.n = n self.n self n n self.s = 0 self.s self s 0 self.t = 0 self.t self t 0 self self n n def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

     next ret = p+1 ret p+1 p 1 if ret >= self.n:
            ret = 0
         ret >= self.n ret self.n self n ret = 0 ret 0 return ret ret self self p p def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

     enqueue if self.next(self.s) == self.t:
            raise Exception("Overflow")
         self.next(self.s) == self.t self.next(self.s) self.next self next self.s self s self.t self t raise Exception("Overflow") Exception("Overflow") Exception "Overflow" self.values[self.s] = x self.values[self.s] self.values self values self.s self s x self.s = self.next(self.s) self.s self s self.next(self.s) self.next self next self.s self s self self x x def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret dequeue if self.s == self.t:
            raise Exception("Underflow")
         self.s == self.t self.s self s self.t self t raise Exception("Underflow") Exception("Underflow") Exception "Underflow" ret = self.values[self.t] ret self.values[self.t] self.values self values self.t self t self.t = self.next(self.t) self.t self t self.next(self.t) self.next self next self.t self t return ret ret self self n, q = map(int, raw_input().split(' ')) n map(int, raw_input().split(' ')) map int raw_input().split(' ') ().split () raw_input split ' ' q queue = Queue(n+1) queue Queue(n+1) Queue n+1 n 1 for _ in range(n):
    name, time = raw_input().split(' ')
    time = int(time)
    queue.enqueue((name, time)) _ range(n) range n name, time = raw_input().split(' ') name raw_input().split(' ') ().split () raw_input split ' ' time time = int(time) time int(time) int time queue.enqueue((name, time)) queue.enqueue queue enqueue (name, time) name time completed = [] completed [] cur = 0 cur 0 while len(completed) < n:
    name, time = queue.dequeue()
    res = time-q
    if res <= 0:
        cur += time
        completed.append((name, cur))
    else:
        cur += q
        queue.enqueue((name, res)) len(completed) < n len(completed) len completed n name, time = queue.dequeue() name queue.dequeue() queue.dequeue queue dequeue time res = time-q res time-q time q if res <= 0:
        cur += time
        completed.append((name, cur))
    else:
        cur += q
        queue.enqueue((name, res)) res <= 0 res 0 cur += time cur time completed.append((name, cur)) completed.append completed append (name, cur) name cur cur += q cur q queue.enqueue((name, res)) queue.enqueue queue enqueue (name, res) name res for name, time in completed:
    print name, time name time completed print name time q = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) q cur += q q cur name, time = queue.dequeue() queue.dequeue() name res = time-q time-q res cur += time time cur time = raw_input().split(' ') raw_input().split(' ') time name, time = raw_input().split(' ') raw_input().split(' ') name completed = [] [] completed n, q = map(int, raw_input().split(' ')) map(int, raw_input().split(' ')) n time = int(time) int(time) time queue = Queue(n+1) Queue(n+1) queue class Queue:
    def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

    def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

    def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

    def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret class Queue:
    def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

    def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

    def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

    def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret Queue time = queue.dequeue() queue.dequeue() time cur = 0 0 cur
class Queue:
    def __init__(self, n):
        self.values = [None]*n
        self.n = n
        self.s = 0
        self.t = 0

    def next(self, p):
        ret = p+1
        if ret >= self.n:
            ret = 0
        return ret

    def enqueue(self, x):
        if self.next(self.s) == self.t:
            raise Exception("Overflow")
        self.values[self.s] = x
        self.s = self.next(self.s)

    def dequeue(self):
        if self.s == self.t:
            raise Exception("Underflow")
        ret = self.values[self.t]
        self.t = self.next(self.t)
        return ret

n, q = map(int, raw_input().split(' '))
queue = Queue(n+1)
for _ in range(n):
    name, time = raw_input().split(' ')
    time = int(time)
    queue.enqueue((name, time))

completed = []
cur = 0
while len(completed) < n:
    name, time = queue.dequeue()
    res = time-q
    if res <= 0:
        cur += time
        completed.append((name, cur))
    else:
        cur += q
        queue.enqueue((name, res))

for name, time in completed:
    print name, time