#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-5;
const double PI = acos(-1);
const long long mod = 998244353;
const int INF = 0x3f3f3f3f;
inline int sgn(double a) { return a < -EPS ? -1 : a > EPS; }
inline int cmp(double a, double b) { return sgn(a - b); }
const int MAXN = 2e5 + 10;
int m, n, k;
vector<int> vec[MAXN];
int rt;
int u[MAXN], v[MAXN], key[MAXN];
int val[10][10];
int in[10];
int ans;
void check() {
  int sum = 0;
  for (int i = 1; i <= k; i++) sum += val[i][in[i]];
  if (sum == rt) ++ans;
}
void dfs(int now) {
  if (now == k + 1) return check();
  for (int i = 1; i <= now; i++) {
    in[now] = i;
    dfs(now + 1);
  }
}
void solve() {
  dfs(1);
  printf("%d\n", ans);
}
void init() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    u[z] = x;
    v[z] = y;
  }
  for (int i = 1; i <= n; i++) rt += (key[i] = rand());
  for (int i = 1; i <= m; i++) vec[u[i]].push_back(v[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < vec[i].size(); j++)
      val[vec[i].size()][j + 1] += key[vec[i][j]];
  }
}
signed main() {
  int T;
  T = 1;
  for (int i = 1; i <= T; i++) {
    init();
    solve();
  }
  return 0;
}
