#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
long long id[10][10];
vector<pair<int, int>> G[N];
vector<int> rG[N];
int on[105];
long long B[105];
int ans;
int n, m, K;
void solve(int pos, long long mask, int cnt) {
  if (pos > K) {
    if (cnt == n) ans++;
    return;
  }
  for (int i = 1; i <= pos; i++) {
    if ((mask >> id[pos][i]) & 1LL) continue;
    solve(pos + 1, mask | B[id[pos][i]], cnt + on[id[pos][i]]);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> K;
  int idx = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = 1; j <= i; j++) {
      id[i][j] = idx++;
    }
  }
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({w, v});
    rG[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    sort(G[i].begin(), G[i].end());
  }
  vector<vector<int>> cnt(K + 1, vector<int>(K + 1));
  long long blocked = 0;
  for (int i = 1; i <= n; i++) {
    for (int u : rG[i]) {
      for (int j = 0; j < G[u].size(); j++) {
        if (G[u][j].second == i) {
          cnt[G[u].size()][j + 1]++;
          break;
        }
      }
    }
    long long mask = 0;
    for (int k = 1; k <= K; k++) {
      for (int l = 1; l <= k; l++) {
        if (cnt[k][l] > 1) {
          blocked |= (1LL << id[k][l]);
        } else if (cnt[k][l]) {
          mask |= (1LL << id[k][l]);
          on[id[k][l]]++;
        }
      }
    }
    for (long long k = 0; k < idx; k++) {
      if ((mask >> k) & 1LL) {
        B[k] |= mask;
      }
    }
    for (int k = 1; k <= K; k++) {
      for (int l = 1; l <= k; l++) {
        cnt[k][l] = 0;
      }
    }
  }
  solve(1, blocked, 0);
  cout << ans << endl;
  return 0;
}
