#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
long long n, m, k, ans, sum[13][13], ss, rd[N];
vector<pair<long long, long long> > out[N];
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void dfs(long long x, long long s) {
  if (x == k + 1) {
    if (s == ss) ans++;
    return;
  }
  for (long long i = 0; i < x; i++) dfs(x + 1, s + sum[x][i]);
}
signed main() {
  n = read(), m = read(), k = read();
  for (long long i = 1; i <= m; i++) {
    long long x = read(), y = read(), z = read();
    out[x].push_back(make_pair(z, y));
  }
  for (long long i = 1; i <= n; i++) {
    long long x = rand();
    long long y = rand();
    long long z = rand();
    rd[i] = x * y + z;
    ss += rd[i];
  }
  for (long long i = 1; i <= n; i++) sort(out[i].begin(), out[i].end());
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j < out[i].size(); j++)
      sum[out[i].size()][j] += rd[out[i][j].second];
  }
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
