class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x

n, q = input().split(" ")
n = int(n)
q = int(q)
q_name = queue()
q_val = queue()
for i in range(n):
    name, t = input().split(" ")
    t = int(t)
    q_name.enqueue(name)
    q_val.enqueue(t)

results = []
end_time = 0
while True:
    process_val = q_val.dequeue()
    process_name = q_name.dequeue()
    if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
    if q_val.head == q_val.tail:
        break

for v in results:
    print("{} {}".format(v[0],v[1])) class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x queue def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

     __init__ self.head = 0 self.head self head 0 self.tail = 0 self.tail self tail 0 self.MAX = 100000 self.MAX self MAX 100000 [0] for i in range(self.MAX) for i in range(self.MAX) i range(self.MAX) range self.MAX self MAX for i in range(self.MAX) [0] 0 self.Q = [[0] for i in range(self.MAX)] self.Q self Q [[0] for i in range(self.MAX)] self self def is_empty(self):
        return self.head == self.tail

     is_empty return self.head == self.tail self.head == self.tail self.head self head self.tail self tail self self def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

     is_full return self.head == (self.tail + 1) % self.MAX self.head == (self.tail + 1) % self.MAX self.head self head (self.tail + 1) % self.MAX self.tail + 1 self.tail self tail 1 self.MAX self MAX self self def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

     enqueue if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
         self.is_full() self.is_full self is_full raise ValueError("エラー（オーバーフロー）") ValueError("エラー（オーバーフロー）") ValueError "エラー（オーバーフロー）" self.Q[self.tail] = x self.Q[self.tail] self.Q self Q self.tail self tail x if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

     self.tail + 1 == self.MAX self.tail + 1 self.tail self tail 1 self.MAX self MAX self.tail = 0 self.tail self tail 0 self.tail += 1 self.tail self tail 1 self self x x def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x dequeue if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
         self.is_empty() self.is_empty self is_empty raise ValueError("エラー（アンダーフロー）") ValueError("エラー（アンダーフロー）") ValueError "エラー（アンダーフロー）" x = self.Q[self.head] x self.Q[self.head] self.Q self Q self.head self head if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
         self.head + 1 == self.MAX self.head + 1 self.head self head 1 self.MAX self MAX self.head = 0 self.head self head 0 self.head += 1 self.head self head 1 return x x self self n, q = input().split(" ") n input().split(" ") ().split () input split " " q n = int(n) n int(n) int n q = int(q) q int(q) int q q_name = queue() q_name queue() queue q_val = queue() q_val queue() queue for i in range(n):
    name, t = input().split(" ")
    t = int(t)
    q_name.enqueue(name)
    q_val.enqueue(t) i range(n) range n name, t = input().split(" ") name input().split(" ") ().split () input split " " t t = int(t) t int(t) int t q_name.enqueue(name) q_name.enqueue q_name enqueue name q_val.enqueue(t) q_val.enqueue q_val enqueue t results = [] results [] end_time = 0 end_time 0 while True:
    process_val = q_val.dequeue()
    process_name = q_name.dequeue()
    if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
    if q_val.head == q_val.tail:
        break True process_val = q_val.dequeue() process_val q_val.dequeue() q_val.dequeue q_val dequeue process_name = q_name.dequeue() process_name q_name.dequeue() q_name.dequeue q_name dequeue if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
     process_val <= q process_val q end_time += process_val end_time process_val results.append([process_name, end_time]) results.append results append [process_name, end_time] process_name end_time end_time += q end_time q rest_val = process_val - q rest_val process_val - q process_val q q_name.enqueue(process_name) q_name.enqueue q_name enqueue process_name q_val.enqueue(rest_val) q_val.enqueue q_val enqueue rest_val if q_val.head == q_val.tail:
        break q_val.head == q_val.tail q_val.head q_val head q_val.tail q_val tail break for v in results:
    print("{} {}".format(v[0],v[1])) v results print("{} {}".format(v[0],v[1])) print "{} {}".format(v[0],v[1]) "{} {}".format "{} {}" format v[0] v 0 v[1] v 1 end_time = 0 0 end_time process_val = q_val.dequeue() q_val.dequeue() process_val end_time += q q end_time process_name = q_name.dequeue() q_name.dequeue() process_name q = input().split(" ") input().split(" ") q n, q = input().split(" ") input().split(" ") n name, t = input().split(" ") input().split(" ") name class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x queue q_name = queue() queue() q_name t = input().split(" ") input().split(" ") t q = int(q) int(q) q q_val = queue() queue() q_val t = int(t) int(t) t results = [] [] results end_time += process_val process_val end_time rest_val = process_val - q process_val - q rest_val n = int(n) int(n) n
class queue():
    def __init__(self):
        self.head = 0
        self.tail = 0
        self.MAX = 100000
        self.Q = [[0] for i in range(self.MAX)]

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

    def is_full(self):
        return self.head == (self.tail + 1) % self.MAX

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("エラー（オーバーフロー）")
        self.Q[self.tail] = x
        if self.tail + 1 == self.MAX:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("エラー（アンダーフロー）")
        x = self.Q[self.head]
        if self.head + 1 == self.MAX:
            self.head = 0
        else:
            self.head += 1
        return x

n, q = input().split(" ")
n = int(n)
q = int(q)
q_name = queue()
q_val = queue()
for i in range(n):
    name, t = input().split(" ")
    t = int(t)
    q_name.enqueue(name)
    q_val.enqueue(t)

results = []
end_time = 0
while True:
    process_val = q_val.dequeue()
    process_name = q_name.dequeue()
    if process_val <= q:
        end_time += process_val
        results.append([process_name, end_time])
    else:
        end_time += q
        rest_val = process_val - q
        q_name.enqueue(process_name)
        q_val.enqueue(rest_val)
    
    if q_val.head == q_val.tail:
        break

for v in results:
    print("{} {}".format(v[0],v[1]))
