#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using pxx = pair<T, T>;
ll power(ll x, ll y);
const ll sp1 = 1e12 + 39;
const ll sp2 = 1e15 + 1e5 + 11;
const ll INF = 1e18 + 18;
const ll MOD = 1e9 + 7;
const int inf = 2e9 + 9;
const int N = 2e5 + 6;
int n, m, k;
vector<pair<int, int> > v[N];
ll hsh[N];
ll subset[10][10];
ll superset, curset, res;
void genPerm(int x) {
  if (x == k) {
    if (superset == curset) res++;
    return;
  }
  for (int i = 0; i <= x; i++) {
    auto temp = curset;
    (curset += subset[x][i]) %= sp2;
    genPerm(x + 1);
    curset = temp;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int I = 1; I <= m; I++) {
    int A, B, C;
    cin >> A >> B >> C;
    v[A].emplace_back(C, B);
  };
  for (int i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
  hsh[0] = 1;
  for (int i = 1; i <= n; i++) hsh[i] = (hsh[i - 1] * 7) % sp2;
  for (int i = 1; i <= n; i++) superset = (hsh[i] + superset) % sp2;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < v[i].size(); j++)
      (subset[v[i].size() - 1][j] += hsh[v[i][j].second]) %= sp2;
  }
  genPerm(0);
  cout << res << "\n";
}
ll power(ll x, ll y) {
  ll res = 1;
  x %= MOD;
  while (y > 0) {
    if (y & 1) res = (res * x) % MOD;
    y = y >> 1, x = (x * x) % MOD;
  }
  return res;
}
