#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
mt19937 myrand(time(0));
long long n, m, k, ans;
vector<pair<long long, long long> > out[200002], in[200002];
bool bad[50][50];
long long id[50][50];
long long getid(long long i, long long j) { return (i * (i + 1) / 2) + j; }
void rec(long long pos, long long mask) {
  if (pos > k) {
    ans++;
    return;
  }
  for (int i = 0; i < pos; i++) {
    if (bad[pos][i] || mask & id[pos][i]) continue;
    rec(pos + 1, mask | (1ll << getid(pos, i)));
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(), cout.tie();
  cin >> n >> m >> k;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    out[u].push_back({w, v});
  }
  for (int i = 1; i <= n; i++) {
    sort(out[i].begin(), out[i].end());
    if (out[i].empty()) {
      cout << 0 << endl;
      return 0;
    }
    for (int j = 0; j < (int)out[i].size(); j++) {
      in[out[i][j].second].push_back({out[i].size(), j});
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(in[i].begin(), in[i].end());
    vector<pair<long long, long long> > tmp;
    for (int j = 0; j < (int)in[i].size(); j++) {
      if (!tmp.empty() && tmp.back() == in[i][j]) {
        bad[in[i][j].first][in[i][j].second] = 1;
        tmp.pop_back();
      } else
        tmp.push_back(in[i][j]);
    }
    for (int j = 0; j < (int)tmp.size(); j++) {
      for (int l = 0; l < (int)tmp.size(); l++) {
        id[tmp[j].first][tmp[j].second] |=
            (1ll << getid(tmp[l].first, tmp[l].second));
      }
    }
  }
  rec(1, 0);
  cout << ans << endl;
}
