class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

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

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v

n,q = map(int,raw_input().split(' '))
processes = []
for i in range(n):
    n,t = raw_input().split(' ')
    processes.append((n,int(t)))

queue = Queue(processes)

clock = 0
done = []
while not queue.empty():
    p = queue.dequeue()
    n = p[0]
    t = p[1]
    if t <= q:
        clock+=t
        done.append((n,clock))
    else:
        queue.enqueue((n,t-q))
        clock+=q

for p in done:
    print p[0],p[1] class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

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

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v Queue def __init__(self,values):
        self.values = values

     __init__ self.values = values self.values self values values self self values values def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

     empty if len(self.values) == 0:
            return True
        else:
            return False

     len(self.values) == 0 len(self.values) len self.values self values 0 return True True return False False self self def enqueue(self,v):
        self.values.append(v)

     enqueue self.values.append(v) self.values.append self.values self values append v self self v v def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v dequeue if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v len(self.values) <= 0 len(self.values) len self.values self values 0 raise v = self.values[0] v self.values[0] self.values self values 0 del self.values[0] self.values[0] self.values self values 0 return v v 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 processes = [] processes [] for i in range(n):
    n,t = raw_input().split(' ')
    processes.append((n,int(t))) i range(n) range n n,t = raw_input().split(' ') n raw_input().split(' ') ().split () raw_input split ' ' t processes.append((n,int(t))) processes.append processes append (n,int(t)) n int(t) int t queue = Queue(processes) queue Queue(processes) Queue processes clock = 0 clock 0 done = [] done [] while not queue.empty():
    p = queue.dequeue()
    n = p[0]
    t = p[1]
    if t <= q:
        clock+=t
        done.append((n,clock))
    else:
        queue.enqueue((n,t-q))
        clock+=q not queue.empty() queue.empty() queue.empty queue empty p = queue.dequeue() p queue.dequeue() queue.dequeue queue dequeue n = p[0] n p[0] p 0 t = p[1] t p[1] p 1 if t <= q:
        clock+=t
        done.append((n,clock))
    else:
        queue.enqueue((n,t-q))
        clock+=q t <= q t q clock+=t clock t done.append((n,clock)) done.append done append (n,clock) n clock queue.enqueue((n,t-q)) queue.enqueue queue enqueue (n,t-q) n t-q t q clock+=q clock q for p in done:
    print p[0],p[1] p done print p[0] p 0 p[1] p 1 clock+=q q clock done = [] [] done n,t = raw_input().split(' ') raw_input().split(' ') n clock = 0 0 clock n,q = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) n clock+=t t clock processes = [] [] processes t = raw_input().split(' ') raw_input().split(' ') t q = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) q t = p[1] p[1] t n = p[0] p[0] n queue = Queue(processes) Queue(processes) queue p = queue.dequeue() queue.dequeue() p class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

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

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

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

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v Queue
class Queue:
    def __init__(self,values):
        self.values = values

    def empty(self):
        if len(self.values) == 0:
            return True
        else:
            return False

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

    def dequeue(self):
        if len(self.values) <= 0:
            raise
        else:
            v = self.values[0]
            del self.values[0]
            return v

n,q = map(int,raw_input().split(' '))
processes = []
for i in range(n):
    n,t = raw_input().split(' ')
    processes.append((n,int(t)))

queue = Queue(processes)

clock = 0
done = []
while not queue.empty():
    p = queue.dequeue()
    n = p[0]
    t = p[1]
    if t <= q:
        clock+=t
        done.append((n,clock))
    else:
        queue.enqueue((n,t-q))
        clock+=q

for p in done:
    print p[0],p[1]