# -*- coding: utf 8 -*-
# Queue
# 2019. 4/25

LEN = 100005
Q = [0] * LEN
head = 0
tail = 0

class Queue:
    def __init__(self):
        self.name = 0
        self.t = 0

def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN

def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x

if __name__ == '__main__':
    elaps = 0
    n, q = map(int, input().split())
    for i in range(1, n + 1):
        u = Queue()
        name , time = input().split()
        u.name = name
        u.t = int(time)
        Q[i] = u

    head = 1
    tail = n + 1

    while(head != tail):
        u = dequeue()
        c = min(q, u.t)
        u.t -= c
        elaps += c
        if( u.t > 0):
            enqueue(u)
        else:
            print("{} {}".format(u.name, elaps))
 LEN = 100005 LEN 100005 Q = [0] * LEN Q [0] * LEN [0] 0 LEN head = 0 head 0 tail = 0 tail 0 class Queue:
    def __init__(self):
        self.name = 0
        self.t = 0 Queue def __init__(self):
        self.name = 0
        self.t = 0 __init__ self.name = 0 self.name self name 0 self.t = 0 self.t self t 0 self self def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN enqueue global tail Q[tail] = x Q[tail] Q tail x tail = (tail + 1) % LEN tail (tail + 1) % LEN tail + 1 tail 1 LEN x x def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x dequeue global head x = Q[head] x Q[head] Q head head = (head + 1) % LEN head (head + 1) % LEN head + 1 head 1 LEN return x x if __name__ == '__main__':
    elaps = 0
    n, q = map(int, input().split())
    for i in range(1, n + 1):
        u = Queue()
        name , time = input().split()
        u.name = name
        u.t = int(time)
        Q[i] = u

    head = 1
    tail = n + 1

    while(head != tail):
        u = dequeue()
        c = min(q, u.t)
        u.t -= c
        elaps += c
        if( u.t > 0):
            enqueue(u)
        else:
            print("{} {}".format(u.name, elaps)) __name__ == '__main__' __name__ '__main__' elaps = 0 elaps 0 n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q for i in range(1, n + 1):
        u = Queue()
        name , time = input().split()
        u.name = name
        u.t = int(time)
        Q[i] = u

     i range(1, n + 1) range 1 n + 1 n 1 u = Queue() u Queue() Queue name , time = input().split() name input().split() ().split () input split time u.name = name u.name u name name u.t = int(time) u.t u t int(time) int time Q[i] = u Q[i] Q i u head = 1 head 1 tail = n + 1 tail n + 1 n 1 while(head != tail):
        u = dequeue()
        c = min(q, u.t)
        u.t -= c
        elaps += c
        if( u.t > 0):
            enqueue(u)
        else:
            print("{} {}".format(u.name, elaps)) head != tail head tail u = dequeue() u dequeue() dequeue c = min(q, u.t) c min(q, u.t) min q u.t u t u.t -= c u.t u t c elaps += c elaps c if( u.t > 0):
            enqueue(u)
        else:
            print("{} {}".format(u.name, elaps)) u.t > 0 u.t u t 0 enqueue(u) enqueue u print("{} {}".format(u.name, elaps)) print "{} {}".format(u.name, elaps) "{} {}".format "{} {}" format u.name u name elaps n, q = map(int, input().split()) map(int, input().split()) n tail = n + 1 n + 1 tail time = input().split() input().split() time q = map(int, input().split()) map(int, input().split()) q c = min(q, u.t) min(q, u.t) c Q = [0] * LEN [0] * LEN Q LEN = 100005 100005 LEN elaps = 0 0 elaps elaps += c c elaps def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x dequeue u = Queue() Queue() u def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN enqueue u = dequeue() dequeue() u tail = 0 0 tail name , time = input().split() input().split() name class Queue:
    def __init__(self):
        self.name = 0
        self.t = 0 class Queue:
    def __init__(self):
        self.name = 0
        self.t = 0 Queue head = 0 0 head head = 1 1 head
# -*- coding: utf 8 -*-
# Queue
# 2019. 4/25

LEN = 100005
Q = [0] * LEN
head = 0
tail = 0

class Queue:
    def __init__(self):
        self.name = 0
        self.t = 0

def enqueue(x):
    global tail
    Q[tail] = x
    tail = (tail + 1) % LEN

def dequeue():
    global head
    x = Q[head]
    head = (head + 1) % LEN
    return x

if __name__ == '__main__':
    elaps = 0
    n, q = map(int, input().split())
    for i in range(1, n + 1):
        u = Queue()
        name , time = input().split()
        u.name = name
        u.t = int(time)
        Q[i] = u

    head = 1
    tail = n + 1

    while(head != tail):
        u = dequeue()
        c = min(q, u.t)
        u.t -= c
        elaps += c
        if( u.t > 0):
            enqueue(u)
        else:
            print("{} {}".format(u.name, elaps))

