class Queue():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop(0)


queue = Queue()
n, q = tuple([int(x) for x in input().split()])
for _ in range(n):
    tmp = input().split()
    queue.push([tmp[0], int(tmp[1])])

time = 0
while queue.l:
    process = queue.pop()
    if process[1] <= q:
        time += process[1]
        print(' '.join([process[0], str(time)]))
    else:
        time += q
        queue.push([process[0], process[1]-q]) class Queue():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop(0) Queue def __init__(self):
        self.l = []
    
     __init__ self.l = [] self.l self l [] self self def push(self, e):
        self.l.append(e)
        
     push self.l.append(e) self.l.append self.l self l append e self self e e def pop(self):
        return self.l.pop(0) pop return self.l.pop(0) self.l.pop(0) self.l.pop self.l self l pop 0 self self queue = Queue() queue Queue() Queue int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, q = tuple([int(x) for x in input().split()]) n tuple([int(x) for x in input().split()]) tuple [int(x) for x in input().split()] q for _ in range(n):
    tmp = input().split()
    queue.push([tmp[0], int(tmp[1])]) _ range(n) range n tmp = input().split() tmp input().split() ().split () input split queue.push([tmp[0], int(tmp[1])]) queue.push queue push [tmp[0], int(tmp[1])] tmp[0] tmp 0 int(tmp[1]) int tmp[1] tmp 1 time = 0 time 0 while queue.l:
    process = queue.pop()
    if process[1] <= q:
        time += process[1]
        print(' '.join([process[0], str(time)]))
    else:
        time += q
        queue.push([process[0], process[1]-q]) queue.l queue l process = queue.pop() process queue.pop() queue.pop queue pop if process[1] <= q:
        time += process[1]
        print(' '.join([process[0], str(time)]))
    else:
        time += q
        queue.push([process[0], process[1]-q]) process[1] <= q process[1] process 1 q time += process[1] time process[1] process 1 print(' '.join([process[0], str(time)])) print ' '.join([process[0], str(time)]) ' '.join ' ' join [process[0], str(time)] process[0] process 0 str(time) str time time += q time q queue.push([process[0], process[1]-q]) queue.push queue push [process[0], process[1]-q] process[0] process 0 process[1]-q process[1] process 1 q process = queue.pop() queue.pop() process time += process[1] process[1] time n, q = tuple([int(x) for x in input().split()]) tuple([int(x) for x in input().split()]) n queue = Queue() Queue() queue tmp = input().split() input().split() tmp time += q q time q = tuple([int(x) for x in input().split()]) tuple([int(x) for x in input().split()]) q class Queue():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop(0) class Queue():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop(0) Queue time = 0 0 time
class Queue():
    def __init__(self):
        self.l = []
    
    def push(self, e):
        self.l.append(e)
        
    def pop(self):
        return self.l.pop(0)


queue = Queue()
n, q = tuple([int(x) for x in input().split()])
for _ in range(n):
    tmp = input().split()
    queue.push([tmp[0], int(tmp[1])])

time = 0
while queue.l:
    process = queue.pop()
    if process[1] <= q:
        time += process[1]
        print(' '.join([process[0], str(time)]))
    else:
        time += q
        queue.push([process[0], process[1]-q])