class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp)

n, q = map(int, raw_input().split())
qu = Queue()

for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    qu.add({'name':name, 'time':time})

time = 0
while qu.el:
    #print qu.el
    if qu.el[0]['time'] > q:
        qu.action()
        time += q
    else:
        time += qu.el[0]['time']
        print qu.el[0]['name'], time
        qu.delete() class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp) Queue def __init__(self):
        self.el = []
        
     __init__ self.el = [] self.el self el [] self self def add(self, el):
        self.el.append(el)
        
     add self.el.append(el) self.el.append self.el self el append el self self el el def delete(self):
        return self.el.pop(0)
    
     delete return self.el.pop(0) self.el.pop(0) self.el.pop self.el self el pop 0 self self def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp) action self.el[0]['time'] -= q self.el[0]['time'] self.el[0] self.el self el 0 'time' q tmp = self.delete() tmp self.delete() self.delete self delete self.el.append(tmp) self.el.append self.el self el append tmp self self n, q = map(int, raw_input().split()) n map(int, raw_input().split()) map int raw_input().split() ().split () raw_input split q qu = Queue() qu Queue() Queue for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    qu.add({'name':name, 'time':time}) i range(n) range n name, time = raw_input().split() name raw_input().split() ().split () raw_input split time time = int(time) time int(time) int time qu.add({'name':name, 'time':time}) qu.add qu add {'name':name, 'time':time} 'name' 'name' name 'time' 'time' time time = 0 time 0 while qu.el:
    #print qu.el
    if qu.el[0]['time'] > q:
        qu.action()
        time += q
    else:
        time += qu.el[0]['time']
        print qu.el[0]['name'], time
        qu.delete() qu.el qu el if qu.el[0]['time'] > q:
        qu.action()
        time += q
    else:
        time += qu.el[0]['time']
        print qu.el[0]['name'], time
        qu.delete() qu.el[0]['time'] > q qu.el[0]['time'] qu.el[0] qu.el qu el 0 'time' q qu.action() qu.action qu action time += q time q time += qu.el[0]['time'] time qu.el[0]['time'] qu.el[0] qu.el qu el 0 'time' print qu.el[0]['name'] qu.el[0] qu.el qu el 0 'name' time qu.delete() qu.delete qu delete time = 0 0 time qu = Queue() Queue() qu class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp) class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp) Queue time += qu.el[0]['time'] qu.el[0]['time'] time name, time = raw_input().split() raw_input().split() name time = int(time) int(time) time time = raw_input().split() raw_input().split() time time += q q time n, q = map(int, raw_input().split()) map(int, raw_input().split()) n q = map(int, raw_input().split()) map(int, raw_input().split()) q
class Queue():
    def __init__(self):
        self.el = []
        
    def add(self, el):
        self.el.append(el)
        
    def delete(self):
        return self.el.pop(0)
    
    def action(self):
        self.el[0]['time'] -= q
        tmp = self.delete()
        self.el.append(tmp)

n, q = map(int, raw_input().split())
qu = Queue()

for i in range(n):
    name, time = raw_input().split()
    time = int(time)
    qu.add({'name':name, 'time':time})

time = 0
while qu.el:
    #print qu.el
    if qu.el[0]['time'] > q:
        qu.action()
        time += q
    else:
        time += qu.el[0]['time']
        print qu.el[0]['name'], time
        qu.delete()