class Node:
    def __init__(self,v):
        self.v = v
        self.next = None

class Queue:
    def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

    def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
    def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail)

n,q = map(int,raw_input().split(' '))
queue = Queue()
for _ in range(n):
    n,t = raw_input().split(' ')
    t = int(t)
    queue.enqueue((n,t))

c = 0
while queue.size>0:
    n,t = queue.dequeue()
    if t <= q:
        c += t
        print n,c
    else:
        queue.enqueue((n,t-q))
        c += q class Node:
    def __init__(self,v):
        self.v = v
        self.next = None Node def __init__(self,v):
        self.v = v
        self.next = None __init__ self.v = v self.v self v v self.next = None self.next self next None self self v v class Queue:
    def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

    def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
    def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail) Queue def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

     __init__ self.head = None self.head self head None self.tail = None self.tail self tail None self.size = 0 self.size self size 0 self self def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
     enqueue self.size += 1 self.size self size 1 n = Node(v) n Node(v) Node v if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
         self.tail == None self.tail self tail None self.tail = n self.tail self tail n self.tail.next = n self.tail.next self.tail self tail next n self.tail = n self.tail self tail n if self.head == None:
            self.head = self.tail
     self.head == None self.head self head None self.head = self.tail self.head self head self.tail self tail self self v v def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail) dequeue if self.size == 0:
            print 'underflow'
            exit()
         self.size == 0 self.size self size 0 print exit() exit self.size -= 1 self.size self size 1 v = self.head.v v self.head.v self.head self head v self.head = self.head.next self.head self head self.head.next self.head self head next if self.head == None:
            self.tail = None
         self.head == None self.head self head None self.tail = None self.tail self tail None return v v 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 queue = Queue() queue Queue() Queue for _ in range(n):
    n,t = raw_input().split(' ')
    t = int(t)
    queue.enqueue((n,t)) _ range(n) range n n,t = raw_input().split(' ') n raw_input().split(' ') ().split () raw_input split ' ' t t = int(t) t int(t) int t queue.enqueue((n,t)) queue.enqueue queue enqueue (n,t) n t c = 0 c 0 while queue.size>0:
    n,t = queue.dequeue()
    if t <= q:
        c += t
        print n,c
    else:
        queue.enqueue((n,t-q))
        c += q queue.size>0 queue.size queue size 0 n,t = queue.dequeue() n queue.dequeue() queue.dequeue queue dequeue t if t <= q:
        c += t
        print n,c
    else:
        queue.enqueue((n,t-q))
        c += q t <= q t q c += t c t print n c queue.enqueue((n,t-q)) queue.enqueue queue enqueue (n,t-q) n t-q t q c += q c q n,t = raw_input().split(' ') raw_input().split(' ') n t = raw_input().split(' ') raw_input().split(' ') t t = queue.dequeue() queue.dequeue() t queue = Queue() Queue() queue c += q q c class Queue:
    def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

    def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
    def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail) class Queue:
    def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

    def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
    def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail) Queue n,q = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) n c = 0 0 c n,t = queue.dequeue() queue.dequeue() n class Node:
    def __init__(self,v):
        self.v = v
        self.next = None class Node:
    def __init__(self,v):
        self.v = v
        self.next = None Node t = int(t) int(t) t q = map(int,raw_input().split(' ')) map(int,raw_input().split(' ')) q c += t t c
class Node:
    def __init__(self,v):
        self.v = v
        self.next = None

class Queue:
    def __init__(self):
        self.head = None
        self.tail = None
        self.size = 0

    def enqueue(self,v):
        self.size += 1
        n = Node(v)
        if self.tail == None:
            self.tail = n
        else:
            self.tail.next = n
            self.tail = n
        if self.head == None:
            self.head = self.tail
    def dequeue(self):
        if self.size == 0:
            print 'underflow'
            exit()
        self.size -= 1
        v = self.head.v
        self.head = self.head.next
        if self.head == None:
            self.tail = None
        return v

#class Queue:
#    def __init__(self,l):
#        self.values = []
#        self.l = l
#        for _ in range(l):
#            self.values.append(None)
#        self.head = 0
#        self.tail = 0
#    def inc(self,n):
#        if n+1 >= self.l:
#            return 0
#        else:
#            return n+1
#    def enqueue(self,v):
#        if self.inc(self.head) == self.tail:
#            print 'overflow'
#            exit()
#        self.values[self.head] = v
#        self.head = self.inc(self.head)
#    def dequeue(self):
#        if self.head == self.tail:
#            print 'underflow'
#            exit()
#        v = self.values[self.tail]
#        self.tail = self.inc(self.tail)
#        return v
#    def size(self):
#        if self.head >= self.tail:
#            return self.head-self.tail
#        else:
#            self.head + (self.l-self.tail)

n,q = map(int,raw_input().split(' '))
queue = Queue()
for _ in range(n):
    n,t = raw_input().split(' ')
    t = int(t)
    queue.enqueue((n,t))

c = 0
while queue.size>0:
    n,t = queue.dequeue()
    if t <= q:
        c += t
        print n,c
    else:
        queue.enqueue((n,t-q))
        c += q