class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time

queue = []

[n, q] = list(map(int, input().split()))

for i in range(n):
    [name, str_time] = input().split()
    time = int(str_time)
    queue.insert(0, Task(name, time))


elps = 0

while queue != []:
    one = queue.pop()
    a = min(one.time, q)
    one.time -= a
    elps += a
    if one.time > 0:
        queue.insert(0, one)
    else:
        print(one.name, elps) class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time Task def __init__(self, name, time):
        self.name = name
        self.time = time __init__ self.name = name self.name self name name self.time = time self.time self time time self self name name time time queue = [] queue [] [n, q] = list(map(int, input().split())) [n, q] n q list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split for i in range(n):
    [name, str_time] = input().split()
    time = int(str_time)
    queue.insert(0, Task(name, time)) i range(n) range n [name, str_time] = input().split() [name, str_time] name str_time input().split() ().split () input split time = int(str_time) time int(str_time) int str_time queue.insert(0, Task(name, time)) queue.insert queue insert 0 Task(name, time) Task name time elps = 0 elps 0 while queue != []:
    one = queue.pop()
    a = min(one.time, q)
    one.time -= a
    elps += a
    if one.time > 0:
        queue.insert(0, one)
    else:
        print(one.name, elps) queue != [] queue [] one = queue.pop() one queue.pop() queue.pop queue pop a = min(one.time, q) a min(one.time, q) min one.time one time q one.time -= a one.time one time a elps += a elps a if one.time > 0:
        queue.insert(0, one)
    else:
        print(one.name, elps) one.time > 0 one.time one time 0 queue.insert(0, one) queue.insert queue insert 0 one print(one.name, elps) print one.name one name elps a = min(one.time, q) min(one.time, q) a queue = [] [] queue elps = 0 0 elps elps += a a elps class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time Task one = queue.pop() queue.pop() one time = int(str_time) int(str_time) time
class Task:
    def __init__(self, name, time):
        self.name = name
        self.time = time

queue = []

[n, q] = list(map(int, input().split()))

for i in range(n):
    [name, str_time] = input().split()
    time = int(str_time)
    queue.insert(0, Task(name, time))


elps = 0

while queue != []:
    one = queue.pop()
    a = min(one.time, q)
    one.time -= a
    elps += a
    if one.time > 0:
        queue.insert(0, one)
    else:
        print(one.name, elps)