#include <bits/stdc++.h>
using std::vector;
struct Edge {
  int u, v, w;
  int id;
  Edge() {}
  Edge(int u, int v, int w, int id) : u(u), v(v), w(w), id(id) {}
};
int type[200005];
int deg[200005];
vector<Edge> inEdge[200005], outEdge[200005];
int f[15][15];
int ban[55];
int keep[15];
long long pow2[55];
long long banMask[55];
int cnt[55];
int preWork(int k) {
  int total = 0;
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= i; j++) {
      f[i][j] = ++total;
    }
  }
  pow2[0] = 1;
  for (int i = 1; i <= 50; i++) pow2[i] = pow2[i - 1] * 2ll;
  return total;
}
int ans = 0;
void dfs(int p, int n, long long have) {
  for (int i = 1; i <= p; i++) {
    int u = f[p][i];
    if (ban[u]) continue;
    if (have & banMask[u]) continue;
    if (p == n)
      ans++;
    else
      dfs(p + 1, n, have + pow2[u - 1]);
  }
}
int main() {
  int now = 1;
  for (int i = 2; i <= 9; i++) now *= i;
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    deg[u]++;
    outEdge[u].push_back(Edge(u, v, w, i));
    inEdge[v].push_back(Edge(u, v, w, i));
  }
  int total = preWork(k);
  for (int i = 1; i <= n; i++) {
    std::sort(outEdge[i].begin(), outEdge[i].end(),
              [&](Edge& u, Edge& v) { return u.w < v.w; });
    int outd = deg[i];
    int size = outEdge[i].size();
    for (int j = 0; j < size; j++) {
      int u = f[outd][j + 1];
      type[outEdge[i][j].id] = u;
    }
  }
  for (int i = 1; i <= total; i++) banMask[i] = 0;
  for (int i = 1; i <= n; i++) {
    long long have = 0;
    for (Edge edge : inEdge[i]) {
      int uid = type[edge.id];
      have |= pow2[uid - 1];
      cnt[uid]++;
    }
    for (Edge edge : inEdge[i]) {
      int uid = type[edge.id];
      if (cnt[uid] != 1)
        ban[uid] = 1;
      else {
        banMask[uid] |= (have ^ pow2[uid - 1]);
      }
    }
    for (Edge edge : inEdge[i]) {
      int uid = type[edge.id];
      cnt[uid]--;
    }
  }
  ans = 0;
  long long have = 0;
  dfs(1, k, have);
  printf("%d\n", ans);
  return 0;
}
