#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
const int H = 1e9 + 7;
vector<pair<int, int> > g[M];
unsigned long long goal, a[20][20], Hash[M];
int n, m, k, ans;
void dfs(int u, unsigned long long now) {
  if (u == k + 1) {
    ans += (now == goal);
    return;
  }
  for (int i = 1; i <= u; i++) dfs(u + 1, now + a[u][i]);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int u, v, w, i = 1; i <= m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    g[u].push_back(make_pair(w, v));
  }
  Hash[0] = 1, goal = 0;
  for (int i = 1; i <= n; i++) {
    Hash[i] = Hash[i - 1] * H;
    goal += Hash[i];
  }
  for (int i = 1; i <= n; i++) {
    sort(g[i].begin(), g[i].end());
    int tot = g[i].size();
    for (int j = 0; j < tot; j++) a[tot][j + 1] += Hash[g[i][j].second];
  }
  ans = 0;
  dfs(1, 0);
  printf("%d\n", ans);
  return 0;
}
