#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 200050;
int n, m, ans, k;
vector<pair<int, int> > gg[N];
long long lkk, sumv[15][15], bi[N];
void dfs(int now, long long sta) {
  if (now == k + 1) {
    if (sta == lkk) ans++;
    return;
  }
  for (int i = 1; i <= now; i++) dfs(now + 1, (sta + sumv[now][i]) % mod);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1, u, v, w; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    gg[u].push_back(make_pair(w, v));
  }
  for (int i = 1; i <= n; i++) sort(gg[i].begin(), gg[i].end());
  bi[0] = 1;
  for (int i = 1; i <= n; i++) {
    bi[i] = bi[i - 1] * 11451497 % mod;
    lkk = (lkk + bi[i]) % mod;
  }
  for (int i = 1; i <= n; i++) {
    int sz = gg[i].size();
    for (int j = 0; j < sz; j++)
      sumv[sz][j + 1] = (bi[gg[i][j].second] + sumv[sz][j + 1]) % mod;
  }
  dfs(1, 0ll);
  cout << ans << endl;
  return 0;
}
