#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 2e5 + 2, mod = 1e9 + 7;
int n, m, k, pw[N], sum[10][10], arr[10], tot, ans, hs;
vector<pair<int, int> > g[N];
vector<int> versz[10];
void permute(int i) {
  if (i == k + 1) {
    ans += (hs == tot);
    return;
  }
  for (int j = (1); j <= (i); ++j) {
    arr[i] = j;
    hs = (hs + sum[i][j]) % mod;
    permute(i + 1);
    hs = (hs - sum[i][j] + mod) % mod;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k;
  for (int i = (1); i <= (m); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].emplace_back(v, w);
  }
  for (int i = (1); i <= (n); ++i) {
    sort((g[i]).begin(), (g[i]).end(),
         [&](const pair<int, int>& A, const pair<int, int>& B) {
           return A.second < B.second;
         });
    versz[((int)(g[i]).size())].emplace_back(i);
  }
  tot = 0;
  pw[0] = 1;
  for (int i = (1); i <= (n); ++i)
    pw[i] = pw[i - 1] * 1LL * 31 % mod, tot = (tot + pw[i]) % mod;
  for (int i = (1); i <= (k); ++i) {
    for (int j = (1); j <= (i); ++j)
      for (int v : versz[i])
        sum[i][j] = (sum[i][j] + pw[g[v][j - 1].first]) % mod;
  }
  permute(1);
  cout << ans;
  return 0;
}
