def initialize():
    global head, tail


def isEmpty():
    global head, tail
    return head == tail


def isFull():
    global head, tail, MAX
    return head == (tail + 1) % MAX


def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1


def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t


if __name__ == "__main__":
    n, q = map(int, input().split())
    head = 0
    tail = n
    MAX = 100000
    Q = [0]*MAX
    runtime = 0
    for i in range(n):
        name, time = input().split()
        Q[i] = ([name, int(time)])
    while head != tail:
        t_list = dequeue()
        if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime)) def initialize():
    global head, tail initialize global head, tail def isEmpty():
    global head, tail
    return head == tail isEmpty global head, tail return head == tail head == tail head tail def isFull():
    global head, tail, MAX
    return head == (tail + 1) % MAX isFull global head, tail, MAX return head == (tail + 1) % MAX head == (tail + 1) % MAX head (tail + 1) % MAX tail + 1 tail 1 MAX def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1 enqueue global head, tail, Q, MAX if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1 isFull() isFull print("?????????????????????") print "?????????????????????" Q[tail] = x Q[tail] Q tail x if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1 tail + 1 == MAX tail + 1 tail 1 MAX tail = 0 tail 0 tail += 1 tail 1 x x def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t dequeue global head, tail, Q, MAX if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t isEmpty() isEmpty print("??¢??????????????????") print "??¢??????????????????" t = Q[head] t Q[head] Q head if head + 1 == MAX:
            head = 0
        else:
            head += 1
         head + 1 == MAX head + 1 head 1 MAX head = 0 head 0 head += 1 head 1 return t t if __name__ == "__main__":
    n, q = map(int, input().split())
    head = 0
    tail = n
    MAX = 100000
    Q = [0]*MAX
    runtime = 0
    for i in range(n):
        name, time = input().split()
        Q[i] = ([name, int(time)])
    while head != tail:
        t_list = dequeue()
        if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime)) __name__ == "__main__" __name__ "__main__" n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q head = 0 head 0 tail = n tail n MAX = 100000 MAX 100000 Q = [0]*MAX Q [0]*MAX [0] 0 MAX runtime = 0 runtime 0 for i in range(n):
        name, time = input().split()
        Q[i] = ([name, int(time)])
     i range(n) range n name, time = input().split() name input().split() ().split () input split time Q[i] = ([name, int(time)]) Q[i] Q i [name, int(time)] name int(time) int time while head != tail:
        t_list = dequeue()
        if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime)) head != tail head tail t_list = dequeue() t_list dequeue() dequeue if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime)) t_list[1] > q t_list[1] t_list 1 q t_list[1] -= q t_list[1] t_list 1 q runtime += q runtime q enqueue(t_list) enqueue t_list runtime += t_list[1] runtime t_list[1] t_list 1 t_list[1] = 0 t_list[1] t_list 1 0 print(t_list[0] + " " + str(runtime)) print t_list[0] + " " + str(runtime) t_list[0] + " " t_list[0] t_list 0 " " str(runtime) str runtime def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1 def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1 enqueue tail = n n tail def initialize():
    global head, tail def initialize():
    global head, tail initialize n, q = map(int, input().split()) map(int, input().split()) n def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t dequeue runtime = 0 0 runtime name, time = input().split() input().split() name runtime += t_list[1] t_list[1] runtime t_list = dequeue() dequeue() t_list def isEmpty():
    global head, tail
    return head == tail def isEmpty():
    global head, tail
    return head == tail isEmpty q = map(int, input().split()) map(int, input().split()) q Q = [0]*MAX [0]*MAX Q head = 0 0 head time = input().split() input().split() time def isFull():
    global head, tail, MAX
    return head == (tail + 1) % MAX def isFull():
    global head, tail, MAX
    return head == (tail + 1) % MAX isFull MAX = 100000 100000 MAX runtime += q q runtime
def initialize():
    global head, tail


def isEmpty():
    global head, tail
    return head == tail


def isFull():
    global head, tail, MAX
    return head == (tail + 1) % MAX


def enqueue(x):
    global head, tail, Q, MAX
    if isFull():
        print("?????????????????????")
    else:
        Q[tail] = x
        if tail + 1 == MAX:
            tail = 0
        else:
            tail += 1


def dequeue():
    global head, tail, Q, MAX
    if isEmpty():
        print("??¢??????????????????")
    else:
        t = Q[head]
        if head + 1 == MAX:
            head = 0
        else:
            head += 1
        return t


if __name__ == "__main__":
    n, q = map(int, input().split())
    head = 0
    tail = n
    MAX = 100000
    Q = [0]*MAX
    runtime = 0
    for i in range(n):
        name, time = input().split()
        Q[i] = ([name, int(time)])
    while head != tail:
        t_list = dequeue()
        if t_list[1] > q:
            t_list[1] -= q
            runtime += q
            enqueue(t_list)
        else:
            runtime += t_list[1]
            t_list[1] = 0
            print(t_list[0] + " " + str(runtime))