#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int K = 10;
int n, m, k;
vector<pair<int, int> > adj[N];
mt19937 Rand;
int a[N], sum, sto[K][K];
int x[K];
int calc(int p, int val) {
  if (p > k) return (val == sum);
  int res = 0;
  for (int i = 1; i <= p; i++) {
    x[p] = i;
    res += calc(p + 1, val + sto[p][i]);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Rand.seed(time(0));
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    int u, v, c;
    cin >> u >> v >> c;
    adj[u].push_back(make_pair(c, v));
  }
  for (int i = 1; i <= n; i++) {
    a[i] = Rand();
    sum += a[i];
  }
  for (int i = 1; i <= n; i++) {
    sort(adj[i].begin(), adj[i].end());
    int deg = adj[i].size();
    for (int j = 1; j <= deg; j++) sto[deg][j] += a[adj[i][j - 1].second];
  }
  cout << calc(1, 0);
  return 0;
}
