MAX_ARRAY_SIZE = 100000

class Queue:
    array = [None] * MAX_ARRAY_SIZE
    start = end = 0
    def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
    def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
    def isEmpty(self):
        return self.start == self.end
    def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE

n, q = list(map(lambda x: int(x), input().strip().split()))

queue = Queue()

for i in range(n):
    queue.enqueue(input().strip().split())


sum_time = 0
while not queue.isEmpty():
    name, time = queue.dequeue()
    if int(time) <= q:
        sum_time += int(time)
        print(name + ' ' + str(sum_time))
    else:
        queue.enqueue([name, str(int(time) - q)])
        sum_time += q MAX_ARRAY_SIZE = 100000 MAX_ARRAY_SIZE 100000 class Queue:
    array = [None] * MAX_ARRAY_SIZE
    start = end = 0
    def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
    def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
    def isEmpty(self):
        return self.start == self.end
    def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE Queue array = [None] * MAX_ARRAY_SIZE array [None] * MAX_ARRAY_SIZE [None] None MAX_ARRAY_SIZE start = end = 0 start 0 = end = 0 end 0 def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
     enqueue assert not self.isFull(), "オーバーフローが発生しました。" not self.isFull() self.isFull() self.isFull self isFull "オーバーフローが発生しました。" self.array[self.end] = a self.array[self.end] self.array self array self.end self end a if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
     self.end + 1 == MAX_ARRAY_SIZE self.end + 1 self.end self end 1 MAX_ARRAY_SIZE self.end = 0 self.end self end 0 self.end += 1 self.end self end 1 self self a a def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
     dequeue assert not self.isEmpty(), "アンダーフローが発生しました。" not self.isEmpty() self.isEmpty() self.isEmpty self isEmpty "アンダーフローが発生しました。" if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
     (self.start + 1) == MAX_ARRAY_SIZE self.start + 1 self.start self start 1 MAX_ARRAY_SIZE self.start = 0 self.start self start 0 return self.array[MAX_ARRAY_SIZE - 1] self.array[MAX_ARRAY_SIZE - 1] self.array self array MAX_ARRAY_SIZE - 1 MAX_ARRAY_SIZE 1 self.start += 1 self.start self start 1 return self.array[self.start - 1] self.array[self.start - 1] self.array self array self.start - 1 self.start self start 1 self self def isEmpty(self):
        return self.start == self.end
     isEmpty return self.start == self.end self.start == self.end self.start self start self.end self end self self def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE isFull return self.start == (self.end + 1) % MAX_ARRAY_SIZE self.start == (self.end + 1) % MAX_ARRAY_SIZE self.start self start (self.end + 1) % MAX_ARRAY_SIZE self.end + 1 self.end self end 1 MAX_ARRAY_SIZE self self n, q = list(map(lambda x: int(x), input().strip().split())) n list(map(lambda x: int(x), input().strip().split())) list map(lambda x: int(x), input().strip().split()) map lambda x: int(x) int(x) int x x input().strip().split() ().strip().split ().strip() ().strip () input strip split q queue = Queue() queue Queue() Queue for i in range(n):
    queue.enqueue(input().strip().split()) i range(n) range n queue.enqueue(input().strip().split()) queue.enqueue queue enqueue input().strip().split() ().strip().split ().strip() ().strip () input strip split sum_time = 0 sum_time 0 while not queue.isEmpty():
    name, time = queue.dequeue()
    if int(time) <= q:
        sum_time += int(time)
        print(name + ' ' + str(sum_time))
    else:
        queue.enqueue([name, str(int(time) - q)])
        sum_time += q not queue.isEmpty() queue.isEmpty() queue.isEmpty queue isEmpty name, time = queue.dequeue() name queue.dequeue() queue.dequeue queue dequeue time if int(time) <= q:
        sum_time += int(time)
        print(name + ' ' + str(sum_time))
    else:
        queue.enqueue([name, str(int(time) - q)])
        sum_time += q int(time) <= q int(time) int time q sum_time += int(time) sum_time int(time) int time print(name + ' ' + str(sum_time)) print name + ' ' + str(sum_time) name + ' ' name ' ' str(sum_time) str sum_time queue.enqueue([name, str(int(time) - q)]) queue.enqueue queue enqueue [name, str(int(time) - q)] name str(int(time) - q) str int(time) - q int(time) int time q sum_time += q sum_time q MAX_ARRAY_SIZE = 100000 100000 MAX_ARRAY_SIZE sum_time += int(time) int(time) sum_time sum_time = 0 0 sum_time class Queue:
    array = [None] * MAX_ARRAY_SIZE
    start = end = 0
    def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
    def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
    def isEmpty(self):
        return self.start == self.end
    def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE class Queue:
    array = [None] * MAX_ARRAY_SIZE
    start = end = 0
    def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
    def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
    def isEmpty(self):
        return self.start == self.end
    def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE Queue sum_time += q q sum_time n, q = list(map(lambda x: int(x), input().strip().split())) list(map(lambda x: int(x), input().strip().split())) n q = list(map(lambda x: int(x), input().strip().split())) list(map(lambda x: int(x), input().strip().split())) q queue = Queue() Queue() queue time = queue.dequeue() queue.dequeue() time name, time = queue.dequeue() queue.dequeue() name
MAX_ARRAY_SIZE = 100000

class Queue:
    array = [None] * MAX_ARRAY_SIZE
    start = end = 0
    def enqueue(self, a):
        assert not self.isFull(), "オーバーフローが発生しました。"
        self.array[self.end] = a
        if self.end + 1 == MAX_ARRAY_SIZE:
            self.end = 0
        else:
            self.end += 1
    def dequeue(self):
        assert not self.isEmpty(), "アンダーフローが発生しました。"
        if (self.start + 1) == MAX_ARRAY_SIZE:
            self.start = 0
            return self.array[MAX_ARRAY_SIZE - 1]
        else:
            self.start += 1
            return self.array[self.start - 1]
    def isEmpty(self):
        return self.start == self.end
    def isFull(self):
        return self.start == (self.end + 1) % MAX_ARRAY_SIZE

n, q = list(map(lambda x: int(x), input().strip().split()))

queue = Queue()

for i in range(n):
    queue.enqueue(input().strip().split())


sum_time = 0
while not queue.isEmpty():
    name, time = queue.dequeue()
    if int(time) <= q:
        sum_time += int(time)
        print(name + ' ' + str(sum_time))
    else:
        queue.enqueue([name, str(int(time) - q)])
        sum_time += q
