n, q = map(int, input().split())

p = []
time = 0

for i in range(n):
	p.append(input().split())
	p[i][1] = int(p[i][1])

while(len(p) > 0):
	if (p[0][1]<= q):
		time += p[0][1]
		print("{0} {1}".format(p[0][0], time))
		p.pop(0)
	else:
		time += q
		p[0][1] -= q
		p.append(p[0])
		p.pop(0) n, q = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split q p = [] p [] time = 0 time 0 for i in range(n):
	p.append(input().split())
	p[i][1] = int(p[i][1]) i range(n) range n p.append(input().split()) p.append p append input().split() ().split () input split p[i][1] = int(p[i][1]) p[i][1] [i] p i 1 int(p[i][1]) int p[i][1] [i] p i 1 while(len(p) > 0):
	if (p[0][1]<= q):
		time += p[0][1]
		print("{0} {1}".format(p[0][0], time))
		p.pop(0)
	else:
		time += q
		p[0][1] -= q
		p.append(p[0])
		p.pop(0) len(p) > 0 len(p) len p 0 if (p[0][1]<= q):
		time += p[0][1]
		print("{0} {1}".format(p[0][0], time))
		p.pop(0)
	else:
		time += q
		p[0][1] -= q
		p.append(p[0])
		p.pop(0) p[0][1]<= q p[0][1] [0] p 0 1 q time += p[0][1] time p[0][1] [0] p 0 1 print("{0} {1}".format(p[0][0], time)) print "{0} {1}".format(p[0][0], time) "{0} {1}".format "{0} {1}" format p[0][0] [0] p 0 0 time p.pop(0) p.pop p pop 0 time += q time q p[0][1] -= q p[0][1] [0] p 0 1 q p.append(p[0]) p.append p append p[0] p 0 p.pop(0) p.pop p pop 0 time += p[0][1] p[0][1] time p = [] [] p q = map(int, input().split()) map(int, input().split()) q time += q q time n, q = map(int, input().split()) map(int, input().split()) n time = 0 0 time
n, q = map(int, input().split())

p = []
time = 0

for i in range(n):
	p.append(input().split())
	p[i][1] = int(p[i][1])

while(len(p) > 0):
	if (p[0][1]<= q):
		time += p[0][1]
		print("{0} {1}".format(p[0][0], time))
		p.pop(0)
	else:
		time += q
		p[0][1] -= q
		p.append(p[0])
		p.pop(0)