#include <bits/stdc++.h>
using namespace std;
int n, m, k;
long long masks[9][9][1563];
bool good[9][9][9][9];
bool selfgood[9][9];
int ans;
int c[9];
void rec(int cur) {
  if (cur == k) {
    ans++;
    return;
  }
  for (int i = 0; i <= cur; i++) {
    bool ok = selfgood[cur][i];
    for (int j = 0; j < cur && ok; j++)
      if (!good[j][c[j]][cur][i]) {
        ok = false;
        break;
      }
    if (ok) {
      c[cur] = i;
      rec(cur + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  vector<vector<pair<int, int>>> adj(n);
  while (m--) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    adj[u].emplace_back(w, v);
  }
  for (int i = 0; i < n; i++) sort(adj[i].begin(), adj[i].end());
  memset(masks, 0, sizeof(masks));
  memset(selfgood, true, sizeof(selfgood));
  for (int i = 0; i < n; i++) {
    int d = adj[i].size();
    for (int j = 0; j < d; j++) {
      int v = adj[i][j].second;
      int x = v >> 6;
      int y = v & 63;
      if (masks[d - 1][j][x] & (1LL << y)) selfgood[d - 1][j] = false;
      masks[d - 1][j][x] |= (1LL << y);
    }
  }
  memset(good, true, sizeof(good));
  for (int i = 0; i < k; i++)
    for (int j = 0; j <= i; j++)
      for (int kk = i + 1; kk < k; kk++)
        for (int t = 0; t <= kk; t++) {
          bool ok = true;
          for (int a = 0; a < 1563; a++)
            if (masks[i][j][a] & masks[kk][t][a]) {
              ok = false;
              break;
            }
          if (!ok) {
            good[i][j][kk][t] = good[kk][t][i][j] = false;
          }
        }
  ans = 0;
  rec(0);
  cout << ans << "\n";
  return 0;
}
