class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1]


N, Q = (int(n) for n in input().split())
processes = ProcessQueue(N)
for i in range(N):
    process = input().split()
    processes.enqueue((process[0], int(process[1])))

time = 0
while not processes.isEmpty():
    process = processes.dequeue()
    if process[1] - Q <= 0:
        time += process[1]
        print(process[0], time)
    else:
        time += Q
        processes.enqueue((process[0], process[1] - Q))
 class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1] ProcessQueue def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

     __init__ self.MAX = N + 1 self.MAX self MAX N + 1 N 1 self.Q = [(None, None)] * self.MAX self.Q self Q [(None, None)] * self.MAX [(None, None)] (None, None) None None self.MAX self MAX self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self self N N def isEmpty(self):
        return self.head == self.tail

     isEmpty return self.head == self.tail self.head == self.tail self.head self head self.tail self tail self self def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

     enqueue self.Q[self.tail] = p self.Q[self.tail] self.Q self Q self.tail self tail p self.tail += 1 self.tail self tail 1 if self.tail == self.MAX:
            self.tail = 0

     self.tail == self.MAX self.tail self tail self.MAX self MAX self.tail = 0 self.tail self tail 0 self self p p def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1] dequeue self.head += 1 self.head self head 1 if self.head == self.MAX:
            self.head = 0

         self.head == self.MAX self.head self head self.MAX self MAX self.head = 0 self.head self head 0 return self.Q[self.head - 1] self.Q[self.head - 1] self.Q self Q self.head - 1 self.head self head 1 self self int(n) for n in input().split() for n in input().split() n input().split() ().split () input split for n in input().split() int(n) int n N, Q = (int(n) for n in input().split()) N (int(n) for n in input().split()) Q processes = ProcessQueue(N) processes ProcessQueue(N) ProcessQueue N for i in range(N):
    process = input().split()
    processes.enqueue((process[0], int(process[1]))) i range(N) range N process = input().split() process input().split() ().split () input split processes.enqueue((process[0], int(process[1]))) processes.enqueue processes enqueue (process[0], int(process[1])) process[0] process 0 int(process[1]) int process[1] process 1 time = 0 time 0 while not processes.isEmpty():
    process = processes.dequeue()
    if process[1] - Q <= 0:
        time += process[1]
        print(process[0], time)
    else:
        time += Q
        processes.enqueue((process[0], process[1] - Q)) not processes.isEmpty() processes.isEmpty() processes.isEmpty processes isEmpty process = processes.dequeue() process processes.dequeue() processes.dequeue processes dequeue if process[1] - Q <= 0:
        time += process[1]
        print(process[0], time)
    else:
        time += Q
        processes.enqueue((process[0], process[1] - Q)) process[1] - Q <= 0 process[1] - Q process[1] process 1 Q 0 time += process[1] time process[1] process 1 print(process[0], time) print process[0] process 0 time time += Q time Q processes.enqueue((process[0], process[1] - Q)) processes.enqueue processes enqueue (process[0], process[1] - Q) process[0] process 0 process[1] - Q process[1] process 1 Q time += Q Q time N, Q = (int(n) for n in input().split()) (int(n) for n in input().split()) N process = input().split() input().split() process Q = (int(n) for n in input().split()) (int(n) for n in input().split()) Q processes = ProcessQueue(N) ProcessQueue(N) processes time = 0 0 time time += process[1] process[1] time class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1] class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1] ProcessQueue process = processes.dequeue() processes.dequeue() process
class ProcessQueue:
    def __init__(self, N):
        self.MAX = N + 1
        self.Q = [(None, None)] * self.MAX
        self.head = 0
        self.tail = 0

    def isEmpty(self):
        return self.head == self.tail

    def enqueue(self, p):
        self.Q[self.tail] = p
        self.tail += 1
        if self.tail == self.MAX:
            self.tail = 0

    def dequeue(self):
        self.head += 1
        if self.head == self.MAX:
            self.head = 0

        return self.Q[self.head - 1]


N, Q = (int(n) for n in input().split())
processes = ProcessQueue(N)
for i in range(N):
    process = input().split()
    processes.enqueue((process[0], int(process[1])))

time = 0
while not processes.isEmpty():
    process = processes.dequeue()
    if process[1] - Q <= 0:
        time += process[1]
        print(process[0], time)
    else:
        time += Q
        processes.enqueue((process[0], process[1] - Q))

