#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, d, m, k, ans;
int du[200005];
struct nd {
  int v, w;
};
vector<nd> e[200005];
vector<int> dd[10];
bool cmp(nd a, nd b) { return a.w < b.w; }
unsigned long long p[15][15], num[200005], bas = 19491001, sum, now;
void dfs(int ce) {
  int i, j, v;
  bool flag = 0;
  if (ce == k + 1) {
    ans += (now == sum * 2);
    return;
  }
  for (i = 1; i <= ce; i++) {
    now += p[i][ce];
    dfs(ce + 1);
    now -= p[i][ce];
  }
}
int main() {
  int i, j, u, v, w;
  n = read(), m = read(), k = read();
  num[0] = 1;
  for (i = 1; i <= n; i++) num[i] = num[i - 1] * bas, sum += num[i];
  for (i = 1; i <= m; i++) {
    u = read(), v = read(), w = read();
    du[u]++;
    e[u].push_back((nd){v, w});
  }
  for (i = 1; i <= n; i++) sort(e[i].begin(), e[i].end(), cmp);
  for (i = 1; i <= n; i++) dd[du[i]].push_back(i);
  for (i = 1; i <= k; i++)
    for (j = 1; j <= i; j++) {
      for (w = 0; w < dd[i].size(); w++) {
        u = dd[i][w];
        v = e[u][j - 1].v;
        p[j][i] += num[u] + num[v];
      }
    }
  dfs(1);
  cout << ans;
  return 0;
}
