n,q=list(map(int,input().split()))
name=[]
time=[]
sum=0
for i in range(n):

	na,ti=input().split()
	name.append(na)
	time.append(int(ti))
	
	
while len(name)>0:
	na=name.pop(0)
	ti=time.pop(0)
	
	if ti>q:
		sum+=q
		name.append(na)
		time.append(ti-q)
		
	else:
		sum+=ti
		print(na, sum)
		 n,q=list(map(int,input().split())) n list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split q name=[] name [] time=[] time [] sum=0 sum 0 for i in range(n):

	na,ti=input().split()
	name.append(na)
	time.append(int(ti))
	
	 i range(n) range n na,ti=input().split() na input().split() ().split () input split ti name.append(na) name.append name append na time.append(int(ti)) time.append time append int(ti) int ti while len(name)>0:
	na=name.pop(0)
	ti=time.pop(0)
	
	if ti>q:
		sum+=q
		name.append(na)
		time.append(ti-q)
		
	else:
		sum+=ti
		print(na, sum)
		 len(name)>0 len(name) len name 0 na=name.pop(0) na name.pop(0) name.pop name pop 0 ti=time.pop(0) ti time.pop(0) time.pop time pop 0 if ti>q:
		sum+=q
		name.append(na)
		time.append(ti-q)
		
	else:
		sum+=ti
		print(na, sum)
		 ti>q ti q sum+=q sum q name.append(na) name.append name append na time.append(ti-q) time.append time append ti-q ti q sum+=ti sum ti print(na, sum) print na sum time=[] [] time sum=0 0 sum ti=input().split() input().split() ti na=name.pop(0) name.pop(0) na sum+=ti ti sum ti=time.pop(0) time.pop(0) ti n,q=list(map(int,input().split())) list(map(int,input().split())) n name=[] [] name q=list(map(int,input().split())) list(map(int,input().split())) q na,ti=input().split() input().split() na sum+=q q sum
n,q=list(map(int,input().split()))
name=[]
time=[]
sum=0
for i in range(n):

	na,ti=input().split()
	name.append(na)
	time.append(int(ti))
	
	
while len(name)>0:
	na=name.pop(0)
	ti=time.pop(0)
	
	if ti>q:
		sum+=q
		name.append(na)
		time.append(ti-q)
		
	else:
		sum+=ti
		print(na, sum)
		
