#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 200000 + 5;
const int maxk = 9 + 1;
int n, m, k, ans, final_set;
vector<pair<int, int>> edges[maxn];
int hashed_set[maxk][maxk] = {};
int randomized_node_index[maxn] = {};
void insert(int &target_set, int node_index) {
  if (randomized_node_index[node_index] == 0)
    randomized_node_index[node_index] = rand() % MOD + 1;
  target_set = (target_set + randomized_node_index[node_index]) % MOD;
}
int s[maxk] = {};
void cal_ans(int i, int current_t_i) {
  s[i] = (s[i - 1] + hashed_set[i][current_t_i]) % MOD;
  if (i == k) {
    if (s[i] == final_set) ++ans;
    return;
  }
  for (int j = 1; j <= i + 1; ++j) cal_ans(i + 1, j);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  srand(time(0));
  cin >> n >> m >> k;
  int u, v, w;
  for (int i = 1; i <= m; ++i) {
    cin >> u >> v >> w;
    edges[u].push_back(pair<int, int>(w, v));
  }
  for (int i = 1; i <= n; ++i) sort(edges[i].begin(), edges[i].end());
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= edges[i].size(); ++j)
      insert(hashed_set[edges[i].size()][j], edges[i][j - 1].second);
  final_set = 0;
  for (int i = 1; i <= n; ++i) insert(final_set, i);
  ans = 0;
  cal_ans(1, 1);
  cout << ans << endl;
  return 0;
  cout << "fuck";
}
