#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ed[200005];
int n, m, k;
unsigned long long Hash[200005];
unsigned long long H = 1e9 + 7;
unsigned long long a[10][10];
unsigned long long sum;
long long ans = 0;
void dfs(int kk1, unsigned long long s) {
  if (kk1 == k) {
    if (s == sum) {
      ans += 1;
    }
    return;
  }
  for (int i = 0; i < kk1 + 1; i++) {
    dfs(kk1 + 1, s + a[kk1 + 1][i]);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    ed[u].push_back(make_pair(w, v));
  }
  for (int i = 1; i <= n; i++) {
    sort(ed[i].begin(), ed[i].end());
  }
  Hash[1] = 1;
  sum = 1;
  for (int i = 2; i <= n; i++) {
    Hash[i] = Hash[i - 1] * H;
    sum += Hash[i];
  }
  for (int i = 1; i <= n; i++) {
    int tp = ed[i].size();
    for (int j = 0; j < tp; j++) {
      int tpp = ed[i][j].second;
      a[tp][j] += Hash[tpp];
    }
  }
  dfs(1, a[1][0]);
  cout << ans << endl;
  return 0;
}
