# Queue

class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue")

def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed))

main() class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue") MyQueue def __init__(self):
        self.queue = [] # list
        self.top = 0
    
     __init__ self.queue = [] self.queue self queue [] self.top = 0 self.top self top 0 self self def isEmpty(self):
        if self.top==0:
            return True
        return False
    
     isEmpty if self.top==0:
            return True
         self.top==0 self.top self top 0 return True True return False False self self def isFull(self):
        pass

     isFull self self def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
     enqueue self.queue.append(x) self.queue.append self.queue self queue append x self.top += 1 self.top self top 1 self self x x def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue") dequeue if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue") self.top>0 self.top self top 0 self.top -= 1 self.top self top 1 return self.queue.pop(0) self.queue.pop(0) self.queue.pop self.queue self queue pop 0 print("there aren't enough values in Queue") print "there aren't enough values in Queue" self self def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed)) main n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n) for i in range(n) i range(n) range n for i in range(n) list(map(lambda x: int(x) if x.isdigit() else x, input().split())) list map(lambda x: int(x) if x.isdigit() else x, input().split()) map lambda x: int(x) if x.isdigit() else x int(x) if x.isdigit() else x x.isdigit() x.isdigit x isdigit int(x) int x x x input().split() ().split () input split A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ] A [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ] {'name': name, 'time': time} for name, time in A for name, time in A name time A for name, time in A {'name': name, 'time': time} 'name' 'name' name 'time' 'time' time A = [{'name': name, 'time': time} for name, time in A] A [{'name': name, 'time': time} for name, time in A] queue = MyQueue() queue MyQueue() MyQueue for a in A:
        queue.enqueue(a)
     a A queue.enqueue(a) queue.enqueue queue enqueue a elapsed = 0 elapsed 0 while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed)) not queue.isEmpty() queue.isEmpty() queue.isEmpty queue isEmpty job = queue.dequeue() job queue.dequeue() queue.dequeue queue dequeue if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed)) job['time']>q job['time'] job 'time' q elapsed += q elapsed q job['time'] = job['time'] - q job['time'] job 'time' job['time'] - q job['time'] job 'time' q queue.enqueue(job) queue.enqueue queue enqueue job elapsed += job['time'] elapsed job['time'] job 'time' print(job['name']+ ' ' + str(elapsed)) print job['name']+ ' ' + str(elapsed) job['name']+ ' ' job['name'] job 'name' ' ' str(elapsed) str elapsed main() main class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue") class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue") MyQueue def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed)) def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed)) main
# Queue

class MyQueue:
    def __init__(self):
        self.queue = [] # list
        self.top = 0
    
    def isEmpty(self):
        if self.top==0:
            return True
        return False
    
    def isFull(self):
        pass

    def enqueue(self, x):
        self.queue.append(x)
        self.top += 1
    
    def dequeue(self):
        if self.top>0:
            self.top -= 1            
            return self.queue.pop(0)
        else:
            print("there aren't enough values in Queue")

def main():
    n, q = map(int, input().split())
    A = [
        list(map(lambda x: int(x) if x.isdigit() else x, input().split()))
        for i in range(n)
    ]
    A = [{'name': name, 'time': time} for name, time in A]
    queue = MyQueue()
    for a in A:
        queue.enqueue(a)
    elapsed = 0
    while not queue.isEmpty():        
        job = queue.dequeue()        
        if job['time']>q:
            elapsed += q
            job['time'] = job['time'] - q
            queue.enqueue(job)
        else:
            elapsed += job['time']
            print(job['name']+ ' ' + str(elapsed))

main()
