#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > adj[200010];
long long hash1[10][10], hash2[10][10], val[200010];
vector<long long> pres;
long long kk;
long long cnt = 0, ch1 = 0, ch2 = 1;
long long mod = 1000000067;
void solve(long long ind) {
  if (ind > kk) {
    long long sum1 = 0, sum2 = 1;
    for (long long i = 0; i < kk; i++) {
      long long y = pres[i];
      sum1 += hash1[i + 1][y];
      sum2 *= hash2[i + 1][y];
      sum2 %= mod;
    }
    if (sum1 == ch1 && sum2 == ch2) cnt++;
    return;
  }
  for (long long i = 1; i <= ind; i++) {
    pres.push_back(i);
    solve(ind + 1);
    pres.pop_back();
  }
}
signed main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m, k;
  cin >> n >> m >> k;
  kk = k;
  for (long long i = 0; i < m; i++) {
    long long a, b, w;
    cin >> a >> b >> w;
    adj[a].push_back(make_pair(w, b));
  }
  for (long long i = 0; i < 10; i++) {
    for (long long j = 0; j < 10; j++) {
      hash2[i][j] = 1;
    }
  }
  for (long long i = 1; i <= n; i++) {
    ch1 += i * i;
    ch2 *= i;
    ch2 %= mod;
    sort(adj[i].begin(), adj[i].end());
  }
  for (long long i = 1; i <= n; i++) {
    long long s = adj[i].size();
    for (long long j = 0; j < s; j++) {
      long long x = adj[i][j].second;
      hash1[s][j + 1] += x * x;
      hash2[s][j + 1] *= x;
      hash2[s][j + 1] %= mod;
    }
  }
  solve(1);
  cout << cnt;
}
