def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a


n, quantum = map(int, input().split())
queue = []
for i in range(n):
    queue.append(parse(input()))
head = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 1


total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum
 def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a parse name, time = l.split() name l.split() l.split l split time a = [name, int(time)] a [name, int(time)] name int(time) int time return a a l l n, quantum = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split quantum queue = [] queue [] for i in range(n):
    queue.append(parse(input())) i range(n) range n queue.append(parse(input())) queue.append queue append parse(input()) parse input() input head = 0 head 0 def enqueue(x):
    global queue
    queue.append(x) enqueue global queue queue.append(x) queue.append queue append x x x def dequeue():
    global head
    head += 1 dequeue global head head += 1 head 1 total_time, count = 0, 0 total_time 0 count 0 while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum count < n count n y = queue[head][1] - quantum y queue[head][1] - quantum queue[head][1] [head] queue head 1 quantum if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

     y <= 0 y 0 print(str(queue[head][0]) + " " + str(total_time + queue[head][1])) print str(queue[head][0]) + " " + str(total_time + queue[head][1]) str(queue[head][0]) + " " str(queue[head][0]) str queue[head][0] [head] queue head 0 " " str(total_time + queue[head][1]) str total_time + queue[head][1] total_time queue[head][1] [head] queue head 1 dequeue() dequeue total_time += y total_time y count += 1 count 1 queue[head][1] -= quantum queue[head][1] [head] queue head 1 quantum enqueue(queue[head]) enqueue queue[head] queue head dequeue() dequeue total_time += quantum total_time quantum total_time, count = 0, 0 0 total_time queue = [] [] queue total_time += quantum quantum total_time def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a parse total_time += y y total_time count = 0, 0 0 count n, quantum = map(int, input().split()) map(int, input().split()) n y = queue[head][1] - quantum queue[head][1] - quantum y def enqueue(x):
    global queue
    queue.append(x) def enqueue(x):
    global queue
    queue.append(x) enqueue count += 1 1 count head = 0 0 head quantum = map(int, input().split()) map(int, input().split()) quantum def dequeue():
    global head
    head += 1 def dequeue():
    global head
    head += 1 dequeue
def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a


n, quantum = map(int, input().split())
queue = []
for i in range(n):
    queue.append(parse(input()))
head = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 1


total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum

