#include <bits/stdc++.h>
using namespace std;
long long M[2];
struct str {
  long long r[2];
  str(long long x = 0) {
    for (long long i = 0; i < 2; ++i) r[i] = x;
  }
  str& operator+=(str b) {
    for (long long i = 0; i < 2; ++i) r[i] = (r[i] + b.r[i]) % M[i];
    return *this;
  }
  friend str operator+(str a, str b) { return a += b; }
  str& operator-=(str b) {
    for (long long i = 0; i < 2; ++i) r[i] = (r[i] - b.r[i] + M[i]) % M[i];
    return *this;
  }
  friend str operator-(str a, str b) { return a -= b; }
  str& operator*=(str b) {
    for (long long i = 0; i < 2; ++i) r[i] = (1LL * r[i] * b.r[i]) % M[i];
    return *this;
  }
  friend str operator*(str a, str b) { return a *= b; }
};
bool operator==(str a, str b) {
  for (long long i = 0; i < 2; ++i)
    if (a.r[i] != b.r[i]) return false;
  return true;
}
long long n, m, k;
str second[9][9];
long long ans = 0;
str a = 0;
void gen(long long pos, str now) {
  if (pos == k) {
    if (now == a) ans++;
  } else {
    for (long long i = 0; i <= pos; ++i) gen(pos + 1, now + second[pos][i]);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  M[0] = 1000000007;
  M[1] = 1000000009;
  cin >> n >> m >> k;
  vector<vector<pair<long long, long long>>> g(n);
  for (long long i = 0; i < m; ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    g[u].push_back({w, v});
  }
  for (long long i = 0; i < n; ++i) sort(g[i].begin(), g[i].end());
  vector<str> val(n);
  for (long long i = 0; i < n; ++i) val[i] = rand();
  for (long long i = 0; i < k; ++i) {
    for (long long j = 0; j <= i; ++j) {
      for (long long v = 0; v < n; ++v) {
        if (g[v].size() == i + 1)
          second[i][j] = second[i][j] + val[g[v][j].second];
      }
    }
  }
  for (long long i = 0; i < n; ++i) a += val[i];
  gen(0, 0);
  cout << ans;
  return 0;
}
