#include <bits/stdc++.h>
using namespace std;
int n, m, k, u, v, w;
vector<pair<int, int> > g[200000 + 5];
int deg[200000 + 5], a[10];
vector<int> p[10];
unsigned long long s[10][10];
long long r[10][10];
int ans = 0;
unsigned long long h = 1;
long long t = 0;
void dfs(int i, unsigned long long c, long long d) {
  if (i == k + 1) {
    ans += c == h && d == t;
    return;
  }
  for (int j = 0; j < i; j++) dfs(i + 1, c * s[i][j], d + r[i][j]);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(make_pair(w, v));
    deg[u]++;
  }
  for (int i = 1; i <= n; i++) {
    p[deg[i]].push_back(i);
    sort(g[u].begin(), g[u].end());
  }
  for (int i = 1; i <= k; i++)
    for (int j = 0; j < i; j++) {
      s[i][j] = 1;
      r[i][j] = 0;
      for (int k = 0; k < p[i].size(); k++) {
        int u = p[i][k];
        s[i][j] *= g[u][j].second;
        r[i][j] += g[u][j].second;
      }
    }
  for (int i = 1; i <= k; i++) a[i] = i;
  for (int i = 1; i <= n; i++) h *= i;
  for (int i = 1; i <= n; i++) t += i;
  dfs(1, 1, 0);
  cout << ans << endl;
}
