#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int K = 10;
bool two[K][K][K][K];
bool one[K][K];
int n, m, k;
int Go(vector<int>& sofar, int pos) {
  if (pos == k + 1) {
    return 1;
  }
  int ans = 0;
  for (int i = 1; i <= pos; ++i) {
    if (one[i][pos]) continue;
    bool stop = false;
    for (int k = 0; k < sofar.size(); ++k) {
      if (two[sofar[k]][k + 1][i][pos]) {
        stop = true;
        break;
      }
    }
    if (!stop) {
      sofar.push_back(i);
      ans += Go(sofar, pos + 1);
      sofar.pop_back();
    }
  }
  return ans;
}
void Run() {
  cin >> n >> m >> k;
  vector<vector<pii>> out(n, vector<pii>{});
  vector<set<pii>> in(n, set<pii>{});
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    --u, --v;
    out[u].emplace_back(w, v);
  }
  for (int i = 0; i < n; ++i) {
    sort(out[i].begin(), out[i].end());
    for (int j = 0; j < out[i].size(); ++j) {
      out[i][j].first = j + 1;
    }
    for (const auto& [x, y] : out[i]) {
      auto res = in[y].emplace(x, out[i].size());
      if (!res.second) {
        one[x][out[i].size()] = true;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    vector<pii> v(in[i].begin(), in[i].end());
    for (int j = 0; j < v.size(); ++j) {
      for (int k = 0; k < j; ++k) {
        two[v[j].first][v[j].second][v[k].first][v[k].second] = true;
        two[v[k].first][v[k].second][v[j].first][v[j].second] = true;
      }
    }
  }
  vector<int> v;
  cout << Go(v, 1) << '\n';
}
int main() {
  srand(time(0));
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  Run();
  return 0;
}
