#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 200005;
int n, m, k;
vector<pair<int, int>> g[N];
int id[10][10], ne;
vector<int> rest[N];
ll adj[50];
void build() {
  for (int i = 1; i <= n; i++) {
    sort(g[i].begin(), g[i].end(), [](pair<int, int> a, pair<int, int> b) {
      return a.second < b.second;
    });
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= i; j++) {
      id[i][j] = ne++;
    }
  }
  for (int i = 1; i <= n; i++) {
    int sz = (int)g[i].size();
    int j = 1;
    for (auto [v, w] : g[i]) {
      rest[v].push_back(id[sz][j]);
      j++;
    }
  }
  for (int i = 0; i < ne; i++) adj[i] = (1LL << ne) - 1;
  for (int i = 1; i <= n; i++) {
    sort(rest[i].begin(), rest[i].end());
    set<int> sb;
    for (int a : rest[i]) {
      for (int b : sb) {
        adj[a] &= ~(1LL << b);
        adj[b] &= ~(1LL << a);
      }
      sb.insert(a);
    }
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= i; j++)
      for (int w = 1; w <= i; w++)
        if (w != j) {
          adj[id[i][j]] &= ~(1LL << id[i][w]);
        }
  }
}
int ans;
void solve(int i, ll can, ll take) {
  if ((take & can) != take) return;
  if (i == k + 1) {
    ans++;
    return;
  }
  for (int j = 1; j <= i; j++) {
    solve(i + 1, can & adj[id[i][j]], take | (1LL << id[i][j]));
  }
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    g[u].emplace_back(v, w);
  }
  build();
  solve(1, (1LL << ne) - 1, 0);
  cout << ans << endl;
}
