class a(object):
    def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <= self.cur

n, q = input().split()
qe = a()
cur_time = 0

for _ in range(int(n)):
    name, time = input().split()
    qe.enqueue((name, int(time)))

while not qe.is_empty():
    name, time = qe.dequeue()
    if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time)) class a(object):
    def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <= self.cur a def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

     __init__ None for _ in range(buf_size) for _ in range(buf_size) _ range(buf_size) range buf_size for _ in range(buf_size) None self.m = [None for _ in range(buf_size)] self.m self m [None for _ in range(buf_size)] self.ind = 0 self.ind self ind 0 self.cur = 0 self.cur self cur 0 self self buf_size=10000000 buf_size 10000000 def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

     enqueue self.m[self.ind] = elem self.m[self.ind] self.m self m self.ind self ind elem self.ind += 1 self.ind self ind 1 self self elem elem def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

     dequeue if self.is_empty(): raise EOFError('this queue is empty')
         self.is_empty() self.is_empty self is_empty result = self.m[self.cur] result self.m[self.cur] self.m self m self.cur self cur self.cur += 1 self.cur self cur 1 return result result self self def is_empty(self):
        return self.ind <= self.cur is_empty return self.ind <= self.cur self.ind <= self.cur self.ind self ind self.cur self cur self self object n, q = input().split() n input().split() ().split () input split q qe = a() qe a() a cur_time = 0 cur_time 0 for _ in range(int(n)):
    name, time = input().split()
    qe.enqueue((name, int(time))) _ range(int(n)) range int(n) int n name, time = input().split() name input().split() ().split () input split time qe.enqueue((name, int(time))) qe.enqueue qe enqueue (name, int(time)) name int(time) int time while not qe.is_empty():
    name, time = qe.dequeue()
    if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time)) not qe.is_empty() qe.is_empty() qe.is_empty qe is_empty name, time = qe.dequeue() name qe.dequeue() qe.dequeue qe dequeue time if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time)) time > int(q) time int(q) int q cur_time += int(q) cur_time int(q) int q time -= int(q) time int(q) int q qe.enqueue((name, time)) qe.enqueue qe enqueue (name, time) name time cur_time += int(time) cur_time int(time) int time print('{} {}'.format(name, cur_time)) print '{} {}'.format(name, cur_time) '{} {}'.format '{} {}' format name cur_time cur_time += int(q) int(q) cur_time qe = a() a() qe cur_time += int(time) int(time) cur_time time -= int(q) int(q) time q = input().split() input().split() q name, time = qe.dequeue() qe.dequeue() name name, time = input().split() input().split() name cur_time = 0 0 cur_time n, q = input().split() input().split() n time = input().split() input().split() time time = qe.dequeue() qe.dequeue() time class a(object):
    def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <= self.cur class a(object):
    def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <= self.cur a
class a(object):
    def __init__(self, buf_size=10000000):
        self.m = [None for _ in range(buf_size)]
        self.ind = 0
        self.cur = 0

    def enqueue(self, elem):
        self.m[self.ind] = elem
        self.ind += 1

    def dequeue(self):
        if self.is_empty(): raise EOFError('this queue is empty')
        result = self.m[self.cur]
        self.cur += 1
        return result

    def is_empty(self):
        return self.ind <= self.cur

n, q = input().split()
qe = a()
cur_time = 0

for _ in range(int(n)):
    name, time = input().split()
    qe.enqueue((name, int(time)))

while not qe.is_empty():
    name, time = qe.dequeue()
    if time > int(q):
        cur_time += int(q)
        time -= int(q)
        qe.enqueue((name, time))
    else:
        cur_time += int(time)
        print('{} {}'.format(name, cur_time))
