# encoding: utf-8
from collections import deque

def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q])

if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A)  from collections import deque def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q]) round_robin_scheduling t = 0 t 0 while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q]) A process = A.popleft() process A.popleft() A.popleft A popleft if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q]) process[1] <= Q process[1] process 1 Q t += process[1] t process[1] process 1 print(process[0],t) print process[0] process 0 t t += Q t Q A.append([process[0],process[1]-Q]) A.append A append [process[0],process[1]-Q] process[0] process 0 process[1]-Q process[1] process 1 Q N N Q Q A A if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A)  __name__ == '__main__' __name__ '__main__' N,Q = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split Q A = deque() A deque() deque for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

     i range(N) range N a = input() a input() input A.append([a.split()[0],int(a.split()[1])]) A.append A append [a.split()[0],int(a.split()[1])] a.split()[0] a.split() a.split a split 0 int(a.split()[1]) int a.split()[1] a.split() a.split a split 1 round_robin_scheduling(N,Q,A) round_robin_scheduling N Q A a = input() input() a def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q]) def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q]) round_robin_scheduling N,Q = map(int,input().split()) map(int,input().split()) N Q = map(int,input().split()) map(int,input().split()) Q A = deque() deque() A
# encoding: utf-8
from collections import deque

def round_robin_scheduling(N, Q, A):
    t = 0
    while A:
        process = A.popleft()
        if process[1] <= Q:
            t += process[1]
            print(process[0],t) 
        else:
            t += Q
            A.append([process[0],process[1]-Q])

if __name__ == '__main__':
    N,Q = map(int,input().split())
    A = deque()
    for i in range(N):
        a = input()
        A.append([a.split()[0],int(a.split()[1])])

    round_robin_scheduling(N,Q,A) 