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

    def enqueue(self, data):
        self.data.append(data)

    def dequeue(self):
        res = self.data.pop(0)
        return res

    def getLength(self):
        return len(self.data)

n, q = map(int, input().split())
time = 0
processes = Queue()

for i in range(n):
    name, cost = input().split()
    processes.enqueue([name, int(cost)])

while processes.getLength() > 0:
    currentProcess = processes.dequeue()
    processName = currentProcess[0]
    processCost = currentProcess[1]

    if processCost <= q:
        time += processCost
        print(' '.join([processName, str(time)]))
        continue

    time += q
    processes.enqueue([processName, processCost - q]) class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, data):
        self.data.append(data)

    def dequeue(self):
        res = self.data.pop(0)
        return res

    def getLength(self):
        return len(self.data) Queue def __init__(self):
        self.data = []

     __init__ self.data = [] self.data self data [] self self def enqueue(self, data):
        self.data.append(data)

     enqueue self.data.append(data) self.data.append self.data self data append data self self data data def dequeue(self):
        res = self.data.pop(0)
        return res

     dequeue res = self.data.pop(0) res self.data.pop(0) self.data.pop self.data self data pop 0 return res res self self def getLength(self):
        return len(self.data) getLength return len(self.data) len(self.data) len self.data self data self self n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q time = 0 time 0 processes = Queue() processes Queue() Queue for i in range(n):
    name, cost = input().split()
    processes.enqueue([name, int(cost)]) i range(n) range n name, cost = input().split() name input().split() ().split () input split cost processes.enqueue([name, int(cost)]) processes.enqueue processes enqueue [name, int(cost)] name int(cost) int cost while processes.getLength() > 0:
    currentProcess = processes.dequeue()
    processName = currentProcess[0]
    processCost = currentProcess[1]

    if processCost <= q:
        time += processCost
        print(' '.join([processName, str(time)]))
        continue

    time += q
    processes.enqueue([processName, processCost - q]) processes.getLength() > 0 processes.getLength() processes.getLength processes getLength 0 currentProcess = processes.dequeue() currentProcess processes.dequeue() processes.dequeue processes dequeue processName = currentProcess[0] processName currentProcess[0] currentProcess 0 processCost = currentProcess[1] processCost currentProcess[1] currentProcess 1 if processCost <= q:
        time += processCost
        print(' '.join([processName, str(time)]))
        continue

     processCost <= q processCost q time += processCost time processCost print(' '.join([processName, str(time)])) print ' '.join([processName, str(time)]) ' '.join ' ' join [processName, str(time)] processName str(time) str time continue time += q time q processes.enqueue([processName, processCost - q]) processes.enqueue processes enqueue [processName, processCost - q] processName processCost - q processCost q processName = currentProcess[0] currentProcess[0] processName processCost = currentProcess[1] currentProcess[1] processCost name, cost = input().split() input().split() name processes = Queue() Queue() processes currentProcess = processes.dequeue() processes.dequeue() currentProcess time += processCost processCost time time = 0 0 time cost = input().split() input().split() cost q = map(int, input().split()) map(int, input().split()) q class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, data):
        self.data.append(data)

    def dequeue(self):
        res = self.data.pop(0)
        return res

    def getLength(self):
        return len(self.data) class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, data):
        self.data.append(data)

    def dequeue(self):
        res = self.data.pop(0)
        return res

    def getLength(self):
        return len(self.data) Queue n, q = map(int, input().split()) map(int, input().split()) n time += q q time
class Queue:
    def __init__(self):
        self.data = []

    def enqueue(self, data):
        self.data.append(data)

    def dequeue(self):
        res = self.data.pop(0)
        return res

    def getLength(self):
        return len(self.data)

n, q = map(int, input().split())
time = 0
processes = Queue()

for i in range(n):
    name, cost = input().split()
    processes.enqueue([name, int(cost)])

while processes.getLength() > 0:
    currentProcess = processes.dequeue()
    processName = currentProcess[0]
    processCost = currentProcess[1]

    if processCost <= q:
        time += processCost
        print(' '.join([processName, str(time)]))
        continue

    time += q
    processes.enqueue([processName, processCost - q])