local mod = 1000000007 local function badd(x, y) return (x + y) % mod end local n, m, k = io.read("*n", "*n", "*n") local q = n n = 300 local ea, eb, ec = {}, {}, {} for i = 1, m do ea[i], eb[i], ec[i] = io.read("*n", "*n", "*n") end local dp1, dp2 = {}, {} for i = 1, n do dp1[i], dp2[i] = {}, {} dp1[i][1] = 1 for j = 2, k + 1 do dp1[i][j] = 0 end end for iq = 2, q do local src = iq % 2 == 0 and dp1 or dp2 local dst = iq % 2 == 0 and dp2 or dp1 for i = 1, n do for j = 1, k + 1 do dst[i][j] = 0 end end for im = 1, m do local a, b, c = ea[im], eb[im], ec[im] for i = 1, k - c + 1 do dst[b][i + c] = badd(dst[b][i + c], src[a][i]) end end end local tbl = q % 2 == 0 and dp2 or dp1 local ret = 0 for i = 1, n do ret = badd(ret, tbl[i][k + 1]) end print(ret)