import time
def get_input_list():
     return list(map(int, input().split()))


def takes_people(d,k):
	for i in range(len(d)):
		if d[i] < k:
			k -=d[i]
			d[i] = 0
		else:
			d[i] -= k
			break
	return d

def zeros(n):
	return [0 for i in range(n)]

def sum_list(a,b):
	s = a
	for i in range(len(b)):
		s[i] += b[i]
	return s

def mul_list(a,n):
	return [i*n for i in a]

def check(a,b,c):
	for i in range(len(a)):
		if a[i] + b[i] > c[i]:
			return False
	return True

n,t,k = get_input_list()

a = []
b = []
c = []
for _ in range(n):
	ai,bi,ci = get_input_list()
	a.append(ai)
	b.append(bi)
	c.append(ci)

d = zeros(n) # num of people are waiting
d = sum_list(d,a)

result = 0 # num of train appointed
for _ in range(t):
	i = 0 
	while check(d,b,c) != True:
		i = i + 1
		d = takes_people(d, k*i)
	print(_,i)
	d = sum_list(d,b)
	result = result + i
print(result)