#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmax(T &first, T second) {
  first < second ? first = second : T();
}
template <typename T>
void chkmin(T &first, T second) {
  first > second ? first = second : T();
}
template <typename T>
void readint(T &first) {
  first = 0;
  int f = 1;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) first = first * 10 + c - '0';
  first *= f;
}
const int MOD = 998244353;
inline int dmy(int first) { return first >= MOD ? first - MOD : first; }
inline void inc(int &first, int second) { first = dmy(first + second); }
int qmi(int first, int second) {
  int ans = 1;
  for (; second; second >>= 1, first = 1ll * first * first % MOD)
    if (second & 1) ans = 1ll * ans * first % MOD;
  return ans;
}
const int MAXN = 200005, MAXK = 11;
int n, k;
vector<pair<int, int> > G[MAXN];
int f[MAXN][MAXK][MAXK];
bool g[MAXK][MAXK][MAXK][MAXK];
int cur[MAXK], ans = 0;
void dfs(int u) {
  if (u > k) {
    ++ans;
    return;
  }
  for (int i = 1; i <= u; ++i) {
    if (g[u][i][u][i]) continue;
    bool flag = 1;
    for (int v = 1; v < u; ++v)
      if (g[u][i][v][cur[v]]) {
        flag = 0;
        break;
      }
    if (!flag) continue;
    cur[u] = i;
    dfs(u + 1);
  }
}
int main() {
  int E, u, v, c;
  readint(n), readint(E), readint(k);
  while (E--) {
    readint(u), readint(v), readint(c);
    G[u].push_back(make_pair(c, v));
  }
  for (int i = 1; i <= n; ++i) {
    sort(G[i].begin(), G[i].end());
    for (int j = 0; j < G[i].size(); ++j)
      f[G[i][j].second][G[i].size()][j + 1]++;
  }
  for (int i = 1; i <= n; ++i)
    for (int first = 1; first <= k; ++first)
      for (int second = 1; second <= first; ++second) {
        if (!f[i][first][second]) continue;
        for (int u = 1; u < first; ++u)
          for (int v = 1; v <= u; ++v)
            if (f[i][u][v]) g[first][second][u][v] = 1;
        if (f[i][first][second] >= 2) g[first][second][first][second] = 1;
      }
  dfs(1);
  cout << ans << endl;
  return 0;
}
