#include <bits/stdc++.h>
using namespace std;
int n, m, k, d = 0;
int mod[3];
mt19937 mt_rand(
    chrono::high_resolution_clock::now().time_since_epoch().count());
bool dec_sort(int a, int b) { return a > b; }
struct hashing_ {
  int a[3];
  hashing_(long long int y) {
    for (int i = 0; i < 3; i++) {
      a[i] = (y % mod[i] + mod[i]) % mod[i];
    }
  }
  hashing_() {
    a[0] = 0;
    a[1] = 0;
    a[2] = 0;
  }
  hashing_ operator+(hashing_ x) {
    hashing_ res;
    res.a[0] = (a[0] + x.a[0]) % mod[0];
    res.a[1] = ((long long int)a[1] + (long long int)(x.a[1])) % mod[1];
    res.a[2] = (a[2] + x.a[2]) % mod[2];
    return res;
  }
  bool operator==(const hashing_& second) const {
    for (int i = 0; i < 3; i++)
      if (second.a[i] != a[i]) return 0;
    return 1;
  }
} val[200001], val2[10][10], second;
set<pair<int, int>> adj[200001];
void check_sum(int x, hashing_ hs) {
  if (x == k) {
    if (hs == second) d++;
    return;
  }
  for (int i = 1; i <= x + 1; i++) {
    check_sum(x + 1, hs + val2[x + 1][i]);
  }
}
int main() {
  int u, v, w, g, y;
  cin >> n >> m >> k;
  mod[0] = 998244353;
  mod[1] = 1e9 + 7;
  mod[2] = std::uniform_int_distribution<int>(1e8, 1e9)(mt_rand);
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    adj[u].insert(make_pair(w, v));
  }
  std::uniform_int_distribution<long long> rg(1, 1e18);
  for (int i = 1; i <= n; i++) {
    val[i] = hashing_(rg(mt_rand));
  }
  for (int i = 1; i <= n; i++) {
    second = second + val[i];
  }
  set<pair<int, int>>::iterator itr;
  for (int i = 1; i <= n; i++) {
    g = adj[i].size();
    y = 1;
    for (itr = adj[i].begin(); itr != adj[i].end(); ++itr) {
      val2[g][y] = val2[g][y] + val[itr->second];
      y++;
    }
  }
  check_sum(0, hashing_());
  cout << d;
}
