#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
mt19937 mt_rand(time(0));
vector<pair<long long, long long>> g[200005];
long long num[200005], ha[25][25] = {0}, sum = 0, ans = 0, n, m, k;
void DFS(long long now, long long v) {
  if (now == k) {
    ans += (v == sum);
    return;
  }
  int i;
  for (i = 0; i <= now; i++) DFS(now + 1, v ^ ha[now][i]);
}
int main() {
  long long i, j, from, to, cost;
  scanf("%lld%lld%lld", &n, &m, &k);
  for (i = 0; i < m; i++) {
    scanf("%lld%lld%lld", &from, &to, &cost);
    g[from - 1].emplace_back(cost, to - 1);
  }
  for (i = 0; i < n; i++) {
    num[i] = mt_rand();
    sum ^= num[i];
  }
  for (i = 0; i < n; i++) {
    sort(g[i].begin(), g[i].end());
    for (j = 0; j < g[i].size(); j++)
      ha[g[i].size() - 1][j] ^= num[g[i][j].second];
  }
  DFS(0, 0);
  printf("%lld\n", ans);
}
