#include <bits/stdc++.h>
using namespace std;
mt19937 mt_rand(
    chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 2e5;
const int HS = 3;
int MOD[HS];
struct hash_number {
  int v[HS];
  hash_number() { memset(v, 0, sizeof v); }
  hash_number(long long x) {
    for (int i = 0; i < HS; i++) v[i] = (x % MOD[i] + MOD[i]) % MOD[i];
  }
  hash_number operator+(hash_number x) {
    hash_number ret;
    ret.v[0] = (v[0] + x.v[0]) % MOD[0];
    ret.v[1] = ((long long)v[1] * x.v[1]) % MOD[1];
    ret.v[2] = (v[2] + x.v[2]) % MOD[2];
    return ret;
  }
  bool operator==(const hash_number& x) const {
    for (int i = 0; i < HS; i++)
      if (v[i] != x.v[i]) return false;
    return true;
  }
};
vector<pair<int, int> > adj[N + 5];
hash_number tot;
int n;
hash_number val[N + 5];
hash_number hass[15][15];
int ans;
int k;
void dfs(int d, hash_number hsh) {
  if (d == k + 1) {
    if (hsh == tot) ans++;
    return;
  }
  for (int i = 1; i <= d; i++) {
    dfs(d + 1, hsh + hass[d][i]);
  }
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  MOD[0] = 1e9 + 7;
  MOD[1] = 1e9 + 9;
  MOD[2] = std::uniform_int_distribution<int>(1e8, 1e9)(mt_rand);
  int m;
  cin >> n >> m >> k;
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].push_back({w, v});
  }
  std::uniform_int_distribution<long long> rg(1, 1e18);
  for (int i = 1; i <= n; i++) {
    val[i] = hash_number(rg(mt_rand));
    tot = tot + val[i];
  }
  for (int i = 1; i <= n; i++) {
    int deg = adj[i].size();
    sort(adj[i].begin(), adj[i].end());
    for (int j = 0; j < deg; j++) {
      hass[deg][j + 1] = hass[deg][j + 1] + val[adj[i][j].second];
    }
  }
  ans = 0;
  hash_number h;
  dfs(1, h);
  cout << ans << endl;
  return 0;
}
