#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int long long
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

vector<vector<pint>> g (300);
int n, m, k;
int ans = 0;
void solve (int i, int cnt, int sum) {
    if (cnt == n) {
        if (sum == k) {
            ans++;
        }
        return;
    }
    if (g[i].size() == 0) return;
    for (auto j : g[i]) {
        solve (j.second, cnt + 1, sum + j.first);
    }
}

signed main() {
    cin >> n >> m >> k;
    const int mod = 1e9 + 7;
    int p[m], q[m], c[m];
    rep (i, 0, m) {
        cin >> p[i] >> q[i] >> c[i];
        g[--p[i]].push_back ({c[i], --q[i]});
    }
    rep (i, 0, 300) { solve (i, 1, 0); }
    cout << ans << "\n";
}