n,t = map(int, input().split())
Task=[]
for i in range(n):
    nm,le= map(str, input().split())
    Task.append([nm,le])
T=0
while n >0:
    k = Task.pop(0)
    k[1]=int(k[1])
    if k[1] > t:
        k[1]=k[1]-t
        T=T+t
        Task.append(k)
        n = len(Task)
    else:
        T=T+k[1]
        k[1]=T
        print(' '.join(map(str, k)))
        n = len(Task) n,t = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split t Task=[] Task [] for i in range(n):
    nm,le= map(str, input().split())
    Task.append([nm,le]) i range(n) range n nm,le= map(str, input().split()) nm map(str, input().split()) map str input().split() ().split () input split le Task.append([nm,le]) Task.append Task append [nm,le] nm le T=0 T 0 while n >0:
    k = Task.pop(0)
    k[1]=int(k[1])
    if k[1] > t:
        k[1]=k[1]-t
        T=T+t
        Task.append(k)
        n = len(Task)
    else:
        T=T+k[1]
        k[1]=T
        print(' '.join(map(str, k)))
        n = len(Task) n >0 n 0 k = Task.pop(0) k Task.pop(0) Task.pop Task pop 0 k[1]=int(k[1]) k[1] k 1 int(k[1]) int k[1] k 1 if k[1] > t:
        k[1]=k[1]-t
        T=T+t
        Task.append(k)
        n = len(Task)
    else:
        T=T+k[1]
        k[1]=T
        print(' '.join(map(str, k)))
        n = len(Task) k[1] > t k[1] k 1 t k[1]=k[1]-t k[1] k 1 k[1]-t k[1] k 1 t T=T+t T T+t T t Task.append(k) Task.append Task append k n = len(Task) n len(Task) len Task T=T+k[1] T T+k[1] T k[1] k 1 k[1]=T k[1] k 1 T print(' '.join(map(str, k))) print ' '.join(map(str, k)) ' '.join ' ' join map(str, k) map str k n = len(Task) n len(Task) len Task T=T+t T+t T T=T+k[1] T+k[1] T nm,le= map(str, input().split()) map(str, input().split()) nm t = map(int, input().split()) map(int, input().split()) t T=0 0 T n = len(Task) len(Task) n n,t = map(int, input().split()) map(int, input().split()) n Task=[] [] Task k = Task.pop(0) Task.pop(0) k n = len(Task) len(Task) n le= map(str, input().split()) map(str, input().split()) le
n,t = map(int, input().split())
Task=[]
for i in range(n):
    nm,le= map(str, input().split())
    Task.append([nm,le])
T=0
while n >0:
    k = Task.pop(0)
    k[1]=int(k[1])
    if k[1] > t:
        k[1]=k[1]-t
        T=T+t
        Task.append(k)
        n = len(Task)
    else:
        T=T+k[1]
        k[1]=T
        print(' '.join(map(str, k)))
        n = len(Task)