s = input().split(" ")
n = int(s[0])
q = int(s[1])

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

queue = []

for i in range(n):
    t = input().split(" ")
    queue.append(Process(t[0], int(t[1])))
   
head = 0
tail = n-1

def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
    
def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x

time = 0

while head != tail:
    w = dequeue()
    if w.time > q:
        w.time = w.time - q
        time = time + q
        enqueue(w)
    else:
        time = time + w.time
        print("{0} {1}".format(w.name, time))
print("{0} {1}".format(queue[head].name, time+queue[head].time)) s = input().split(" ") s input().split(" ") ().split () input split " " n = int(s[0]) n int(s[0]) int s[0] s 0 q = int(s[1]) q int(s[1]) int s[1] s 1 class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time Process 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 [] for i in range(n):
    t = input().split(" ")
    queue.append(Process(t[0], int(t[1])))
    i range(n) range n t = input().split(" ") t input().split(" ") ().split () input split " " queue.append(Process(t[0], int(t[1]))) queue.append queue append Process(t[0], int(t[1])) Process t[0] t 0 int(t[1]) int t[1] t 1 head = 0 head 0 tail = n-1 tail n-1 n 1 def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
     dequeue global head x = queue[head] x queue[head] queue head head = (head + 1) % n head (head + 1) % n head + 1 head 1 n return x x def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x enqueue global tail tail = (tail + 1) % n tail (tail + 1) % n tail + 1 tail 1 n queue[tail] = x queue[tail] queue tail x x x time = 0 time 0 while head != tail:
    w = dequeue()
    if w.time > q:
        w.time = w.time - q
        time = time + q
        enqueue(w)
    else:
        time = time + w.time
        print("{0} {1}".format(w.name, time)) head != tail head tail w = dequeue() w dequeue() dequeue if w.time > q:
        w.time = w.time - q
        time = time + q
        enqueue(w)
    else:
        time = time + w.time
        print("{0} {1}".format(w.name, time)) w.time > q w.time w time q w.time = w.time - q w.time w time w.time - q w.time w time q time = time + q time time + q time q enqueue(w) enqueue w time = time + w.time time time + w.time time w.time w time print("{0} {1}".format(w.name, time)) print "{0} {1}".format(w.name, time) "{0} {1}".format "{0} {1}" format w.name w name time print("{0} {1}".format(queue[head].name, time+queue[head].time)) print "{0} {1}".format(queue[head].name, time+queue[head].time) "{0} {1}".format "{0} {1}" format queue[head].name [head] queue head name time+queue[head].time time queue[head].time [head] queue head time q = int(s[1]) int(s[1]) q def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x enqueue time = time + w.time time + w.time time queue = [] [] queue time = time + q time + q time time = 0 0 time tail = n-1 n-1 tail def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
     def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
     dequeue class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time class Process:
    def __init__(self, name, time):
        self.name = name
        self.time = time Process s = input().split(" ") input().split(" ") s n = int(s[0]) int(s[0]) n w = dequeue() dequeue() w head = 0 0 head t = input().split(" ") input().split(" ") t
s = input().split(" ")
n = int(s[0])
q = int(s[1])

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

queue = []

for i in range(n):
    t = input().split(" ")
    queue.append(Process(t[0], int(t[1])))
   
head = 0
tail = n-1

def dequeue():
    global head
    x = queue[head]
    head = (head + 1) % n
    return x
    
def enqueue(x):
    global tail
    tail = (tail + 1) % n
    queue[tail] = x

time = 0

while head != tail:
    w = dequeue()
    if w.time > q:
        w.time = w.time - q
        time = time + q
        enqueue(w)
    else:
        time = time + w.time
        print("{0} {1}".format(w.name, time))
print("{0} {1}".format(queue[head].name, time+queue[head].time))