# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B
# Queue
# Result:
import sys

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

    def __str__(self):
        return '%s(%d)' % (self.name, self.time)


class Queue:
    def __init__(self):
        self.store = []

    def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

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

    def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main
vals = sys.stdin.readline().rstrip().split(' ')
n, q = map(int, vals)

queue = Queue()
for i in range(0, n):
    pname, ptime = sys.stdin.readline().rstrip().split(' ')
    queue.enqueue(Process(pname, int(ptime)))

time = 0
while not queue.is_empty():
    p = queue.dequeue()
    if p.time > q:
        p.time -= q
        queue.enqueue(p)
        time += q
    else:
        time += p.time
        print '%s %d' % (p.name, time) import sys sys class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

    def __str__(self):
        return '%s(%d)' % (self.name, self.time) Process def __init__(self, name, time):
        self.name = name
        self.time = time

     __init__ self.name = name self.name self name name self.time = time self.time self time time self self name name time time def __str__(self):
        return '%s(%d)' % (self.name, self.time) __str__ return '%s(%d)' % (self.name, self.time) '%s(%d)' % (self.name, self.time) '%s(%d)' (self.name, self.time) self.name self name self.time self time self self class Queue:
    def __init__(self):
        self.store = []

    def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

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

    def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main Queue def __init__(self):
        self.store = []

     __init__ self.store = [] self.store self store [] self self def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

     __str__ """From head to tail""" str_val = '' str_val '' for var in self.store:
            str_val += str(var) + '\n'
         var self.store self store str_val += str(var) + '\n' str_val str(var) + '\n' str(var) str var '\n' return str_val.rstrip() str_val.rstrip() str_val.rstrip str_val rstrip self self def enqueue(self, v):
        self.store.append(v)

     enqueue self.store.append(v) self.store.append self.store self store append v self self v v def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

     dequeue if self.is_empty():
            return None
         self.is_empty() self.is_empty self is_empty return None None return self.store.pop(0) self.store.pop(0) self.store.pop self.store self store pop 0 self self def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main is_empty if len(self.store) == 0:
            return True
        else:
            return False


### main len(self.store) == 0 len(self.store) len self.store self store 0 return True True return False False self self vals = sys.stdin.readline().rstrip().split(' ') vals sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split ' ' n, q = map(int, vals) n map(int, vals) map int vals q queue = Queue() queue Queue() Queue for i in range(0, n):
    pname, ptime = sys.stdin.readline().rstrip().split(' ')
    queue.enqueue(Process(pname, int(ptime))) i range(0, n) range 0 n pname, ptime = sys.stdin.readline().rstrip().split(' ') pname sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip split ' ' ptime queue.enqueue(Process(pname, int(ptime))) queue.enqueue queue enqueue Process(pname, int(ptime)) Process pname int(ptime) int ptime time = 0 time 0 while not queue.is_empty():
    p = queue.dequeue()
    if p.time > q:
        p.time -= q
        queue.enqueue(p)
        time += q
    else:
        time += p.time
        print '%s %d' % (p.name, time) not queue.is_empty() queue.is_empty() queue.is_empty queue is_empty p = queue.dequeue() p queue.dequeue() queue.dequeue queue dequeue if p.time > q:
        p.time -= q
        queue.enqueue(p)
        time += q
    else:
        time += p.time
        print '%s %d' % (p.name, time) p.time > q p.time p time q p.time -= q p.time p time q queue.enqueue(p) queue.enqueue queue enqueue p time += q time q time += p.time time p.time p time print '%s %d' % (p.name, time) '%s %d' (p.name, time) p.name p name time p = queue.dequeue() queue.dequeue() p ptime = sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split(' ') ptime class Queue:
    def __init__(self):
        self.store = []

    def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

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

    def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main class Queue:
    def __init__(self):
        self.store = []

    def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

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

    def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main Queue vals = sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split(' ') vals q = map(int, vals) map(int, vals) q queue = Queue() Queue() queue pname, ptime = sys.stdin.readline().rstrip().split(' ') sys.stdin.readline().rstrip().split(' ') pname time += p.time p.time time time = 0 0 time class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

    def __str__(self):
        return '%s(%d)' % (self.name, self.time) class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

    def __str__(self):
        return '%s(%d)' % (self.name, self.time) Process n, q = map(int, vals) map(int, vals) n time += q q time
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_B
# Queue
# Result:
import sys

class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time

    def __str__(self):
        return '%s(%d)' % (self.name, self.time)


class Queue:
    def __init__(self):
        self.store = []

    def __str__(self):
        """From head to tail"""
        str_val = ''
        for var in self.store:
            str_val += str(var) + '\n'
        return str_val.rstrip()

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

    def dequeue(self):
        if self.is_empty():
            return None
        return self.store.pop(0)

    def is_empty(self):
        if len(self.store) == 0:
            return True
        else:
            return False


### main
vals = sys.stdin.readline().rstrip().split(' ')
n, q = map(int, vals)

queue = Queue()
for i in range(0, n):
    pname, ptime = sys.stdin.readline().rstrip().split(' ')
    queue.enqueue(Process(pname, int(ptime)))

time = 0
while not queue.is_empty():
    p = queue.dequeue()
    if p.time > q:
        p.time -= q
        queue.enqueue(p)
        time += q
    else:
        time += p.time
        print '%s %d' % (p.name, time)