#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
const int MAXK = 9;
const int MAXH = 89;
int n, m, k;
int ans = 0;
int c[MAXK + 5];
vector<int> in[MAXN + 5];
bool bad[MAXH + 5][MAXH + 5];
vector<pair<int, int> > G[MAXN + 5];
void gen(int i) {
  if (i == k + 1) {
    ans++;
    return;
  }
  for (int j = 0; j < i; ++j) {
    int hash = i * 9 + j;
    if (bad[hash][hash]) continue;
    bool flag = true;
    for (int k = 1; k < i; ++k) {
      if (bad[c[k]][hash]) {
        flag = false;
        break;
      }
    }
    if (!flag) continue;
    c[i] = hash;
    gen(i + 1);
  }
}
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    G[u].push_back(make_pair(w, v));
  }
  for (int i = 1; i <= n; ++i) {
    sort(G[i].begin(), G[i].end());
    int sz = G[i].size();
    for (int j = 0; j < sz; ++j) {
      in[G[i][j].second].push_back(sz * 9 + j);
    }
  }
  for (int i = 1; i <= n; ++i) {
    int sz = in[i].size();
    if (sz == 0) {
      cout << 0 << '\n';
      return 0;
    }
    vector<int> v = in[i];
    in[i].clear();
    in[i].push_back(v[0]);
    for (int j = 1; j < sz; ++j) {
      if (v[j] == v[j - 1])
        bad[v[j]][v[j]] = true;
      else
        in[i].push_back(v[j]);
    }
    sz = in[i].size();
    for (int j = 0; j < sz; ++j) {
      for (int k = j + 1; k < sz; ++k) {
        bad[in[i][j]][in[i][k]] = bad[in[i][k]][in[i][j]] = true;
      }
    }
  }
  gen(1);
  cout << ans << '\n';
  return 0;
}
