class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1)

p_queue = Queue()
e_time = 0

n, q = map(int, input().split())

for i in range(n):
    process = input().split()
    process[1] = int(process[1])
    p_queue.enqueue(process)

while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        print(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process) class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1) Queue def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

     __init__ self.size = 0 self.size self size 0 self.Max = 100000 self.Max self Max 100000 self.queue = [None] self.queue self queue [None] None self self def isEmpty(self):
        return self.size == 0

     isEmpty return self.size == 0 self.size == 0 self.size self size 0 self self def isFull(self):
        return self.size >= self.Max

     isFull return self.size >= self.Max self.size >= self.Max self.size self size self.Max self Max self self def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

     enqueue if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

     self.isFull() self.isFull self isFull print("Queue overflow!") print "Queue overflow!" self.queue.append(x) self.queue.append self.queue self queue append x self.size += 1 self.size self size 1 self self x x def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1) dequeue if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1) self.isEmpty() self.isEmpty self isEmpty print("Queue underflow!") print "Queue underflow!" self.size -= 1 self.size self size 1 return self.queue.pop(1) self.queue.pop(1) self.queue.pop self.queue self queue pop 1 self self p_queue = Queue() p_queue Queue() Queue e_time = 0 e_time 0 n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q for i in range(n):
    process = input().split()
    process[1] = int(process[1])
    p_queue.enqueue(process) i range(n) range n process = input().split() process input().split() ().split () input split process[1] = int(process[1]) process[1] process 1 int(process[1]) int process[1] process 1 p_queue.enqueue(process) p_queue.enqueue p_queue enqueue process while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        print(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process) not p_queue.isEmpty() p_queue.isEmpty() p_queue.isEmpty p_queue isEmpty process = p_queue.dequeue() process p_queue.dequeue() p_queue.dequeue p_queue dequeue if process[1] <= q:
        e_time += process[1]
        print(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process) process[1] <= q process[1] process 1 q e_time += process[1] e_time process[1] process 1 print(process[0], e_time) print process[0] process 0 e_time e_time += q e_time q process[1] -= q process[1] process 1 q p_queue.enqueue(process) p_queue.enqueue p_queue enqueue process q = map(int, input().split()) map(int, input().split()) q e_time += q q e_time process = input().split() input().split() process e_time = 0 0 e_time process = p_queue.dequeue() p_queue.dequeue() process p_queue = Queue() Queue() p_queue class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1) class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1) Queue n, q = map(int, input().split()) map(int, input().split()) n e_time += process[1] process[1] e_time
class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1)

p_queue = Queue()
e_time = 0

n, q = map(int, input().split())

for i in range(n):
    process = input().split()
    process[1] = int(process[1])
    p_queue.enqueue(process)

while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        print(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process)