n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(len(queue) != 0):
    item = queue.pop(0)
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1]) n, q = map(int , input().split()) n map(int , input().split()) map int input().split() ().split () input split q queue = [] queue [] for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])]) _ range(n) range n line = input().split() line input().split() ().split () input split queue.append([line[0], int(line[1])]) queue.append queue append [line[0], int(line[1])] line[0] line 0 int(line[1]) int line[1] line 1 class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item my_queue def __init__(self, queue):
        self.queue = queue
     __init__ self.queue = queue self.queue self queue queue self self queue queue def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
     enqueue self.queue = self.queue + [item] self.queue self queue self.queue + [item] self.queue self queue [item] item self.queue.append(item) self.queue.append self.queue self queue append item self self item item def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item dequeue if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
         len(self.queue) != 0 len(self.queue) len self.queue self queue 0 item = self.queue[0] item self.queue[0] self.queue self queue 0 self.queue = self.queue[1:] self.queue self queue self.queue[1:] self.queue self queue 1: 1 item = None item None return item item self self time = 0 time 0 finish_task = [] finish_task [] while(len(queue) != 0):
    item = queue.pop(0)
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q]) len(queue) != 0 len(queue) len queue 0 item = queue.pop(0) item queue.pop(0) queue.pop queue pop 0 if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q]) item == None item None break elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
     item[1] <= q item[1] item 1 q time += item[1] time item[1] item 1 finish_task.append([item[0], time]) finish_task.append finish_task append [item[0], time] item[0] item 0 time time += q time q queue.append([item[0], item[1] - q]) queue.append queue append [item[0], item[1] - q] item[0] item 0 item[1] - q item[1] item 1 q for item in finish_task:
    print(item[0], item[1]) item finish_task print(item[0], item[1]) print item[0] item 0 item[1] item 1 queue = [] [] queue time += q q time q = map(int , input().split()) map(int , input().split()) q time += item[1] item[1] time time = 0 0 time n, q = map(int , input().split()) map(int , input().split()) n item = queue.pop(0) queue.pop(0) item class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item my_queue line = input().split() input().split() line finish_task = [] [] finish_task
n, q = map(int , input().split())
queue = []
for _ in range(n):
    line = input().split()
    queue.append([line[0], int(line[1])])

class my_queue:
    def __init__(self, queue):
        self.queue = queue
    def enqueue(self, item):
        self.queue = self.queue + [item]
        self.queue.append(item)
    def dequeue(self):
        if len(self.queue) != 0:
            item = self.queue[0]
            self.queue = self.queue[1:]
        else :
            item = None
        return item


time = 0
finish_task = []

while(len(queue) != 0):
    item = queue.pop(0)
    if item == None:
        break
    elif item[1] <= q:
        time += item[1]
        finish_task.append([item[0], time])
    else :
        time += q
        queue.append([item[0], item[1] - q])

for item in finish_task:
    print(item[0], item[1])