#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, k, d[N], c[N], A[20], ans = 0;
bool G[50][N], M[50][50], valid[50];
struct edge {
  int u, v, w;
} e[N];
bool cmp(edge a, edge b) { return a.w < b.w; }
int getid(int x, int y) { return x * (x - 1) / 2 + y; }
void dfs(int p) {
  if (p > k) {
    ++ans;
    return;
  }
  for (int i = 1; i <= p; ++i) {
    bool flag = true;
    int x = getid(p, i);
    if (!valid[x]) continue;
    for (int j = 1; j <= p - 1; ++j)
      if (!M[A[j]][x]) flag = false;
    if (flag) {
      A[p] = x;
      dfs(p + 1);
    }
  }
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= n; ++i) d[i] = c[i] = 0;
  for (int i = 1; i <= m; ++i)
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w), ++d[e[i].u];
  sort(e + 1, e + m + 1, cmp);
  memset(G, false, sizeof(G));
  memset(valid, true, sizeof(valid));
  for (int i = 1; i <= m; ++i) {
    ++c[e[i].u];
    if (G[getid(d[e[i].u], c[e[i].u])][e[i].v])
      valid[getid(d[e[i].u], c[e[i].u])] = false;
    G[getid(d[e[i].u], c[e[i].u])][e[i].v] = true;
  }
  memset(M, true, sizeof(M));
  int st = getid(k, k);
  for (int u = 1; u <= n; ++u)
    for (int i = 1; i <= st; ++i)
      if (G[i][u] && valid[i])
        for (int j = i + 1; j <= st; ++j)
          if (G[j][u]) M[i][j] = false;
  ans = 0;
  dfs(1);
  printf("%d\n", ans);
  return 0;
}
