#include <bits/stdc++.h>
using namespace std;
int ans = 0;
vector<set<pair<int, int>>> fm;
int n, m, k;
set<pair<int, int>> self_con;
map<pair<int, int>, set<pair<int, int>>> con;
vector<vector<int>> out;
vector<vector<pair<int, int>>> ns;
vector<pair<int, int>> cur;
void dfs(int d) {
  if (d == k + 1) {
    ans += 1;
    return;
  }
  for (int i = 0; i < d; i++) {
    if (self_con.find(make_pair(i, d - 1)) != self_con.end()) continue;
    int rs = 1;
    pair<int, int> mkp = make_pair(i, d - 1);
    for (auto it = cur.begin(); it != cur.end(); it++) {
      if (con[(*it)].find(mkp) != con[(*it)].end()) {
        rs = 0;
        break;
      }
    }
    if (rs == 1) {
      cur.push_back(mkp);
      dfs(d + 1);
      cur.pop_back();
    }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n >> m >> k;
  fm.resize(n);
  ns.resize(n);
  for (int i = 0; i < m; i++) {
    int f, t, w;
    cin >> f >> t >> w;
    f--;
    t--;
    ns[f].push_back(make_pair(w, t));
  }
  for (int i = 0; i < n; i++) {
    sort(ns[i].begin(), ns[i].end());
    int ll = ns[i].size();
    for (int j = 0; j < ll; j++) {
      int t = ns[i][j].second;
      pair<int, int> mkp = make_pair(j, ll - 1);
      if (fm[t].find(mkp) != fm[t].end())
        self_con.insert(mkp);
      else
        fm[t].insert(mkp);
    }
  }
  for (int i = 0; i < n; i++) {
    for (auto j = fm[i].begin(); j != fm[i].end(); j++) {
      auto k = j;
      k++;
      for (; k != fm[i].end(); k++) {
        con[*j].insert(*k);
        con[*k].insert(*j);
      }
    }
  }
  dfs(1);
  cout << ans << endl;
  return 0;
}
