#include <bits/stdc++.h>
const int maxn = 2e5 + 5;
const int p = 131;
const int mo = (1 << 21) - 1;
const int maxk = 10;
using namespace std;
int rd() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = getchar();
  return x * f;
}
int n, m, k, c[maxn], ans, mp[maxk][maxk], e;
vector<pair<int, int> > t[maxn];
void add(int &x, int y) {
  x += y;
  if (x >= mo) x -= mo;
}
bool tmp(pair<int, int> &x, pair<int, int> &y) { return x.second > y.second; }
bool check() {
  int now = 0;
  for (int i = 1; i <= k; i++) add(now, mp[i][c[i]]);
  return now == e;
}
void dfs(int x) {
  if (x == k + 1) {
    if (check()) ans++;
    return;
  }
  for (int i = 1; i <= x; i++) {
    c[x] = i;
    dfs(x + 1);
  }
}
int ksm(int a, int b) {
  int sum = 1;
  for (; b; b >>= 1, a = 1LL * a * a % mo)
    if (b & 1) sum = 1LL * sum * a % mo;
  return sum;
}
int main() {
  n = rd();
  m = rd();
  k = rd();
  for (int u, v, w, i = 1; i <= m; i++) {
    u = rd();
    v = rd();
    w = rd();
    t[u].push_back(make_pair(v, w));
  }
  for (int i = 1; i <= n; i++) {
    sort(t[i].begin(), t[i].end(), tmp);
    int s = t[i].size();
    for (int j = 0; j < s; j++) add(mp[s][j + 1], ksm(p, t[i][j].first));
  }
  for (int i = 1; i <= n; i++) add(e, ksm(p, i));
  dfs(1);
  printf("%d\n", ans);
  return 0;
}
