#include <bits/stdc++.h>
using namespace std;
struct re {
  int x, w;
  const bool operator<(const re &a) const { return w < a.w; }
};
const int M = 1000000000 + 7;
const int N = 200000 + 10;
const int MAX_POSSIBILITES = 50;
int n, m, k, deg[N];
vector<re> e[N];
vector<re> possibilities;
int location[10][10];
int invalid[10][10];
int cntPossibilities;
long long sumBitMask[N];
long long bitmask[MAX_POSSIBILITES];
int cal(int x, long long mask) {
  if (x == k + 1) return 1;
  int res = 0;
  for (int i = (1); (i <= (x)); ++i) {
    if (!invalid[i][x] && (mask & (1LL << location[i][x]))) {
      res += cal(x + 1, (mask & bitmask[location[i][x]]));
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m >> k;
  for (int i = (1); (i <= (m)); ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    e[u].push_back({v, w});
  }
  for (int i = (1); (i <= (k)); ++i) {
    for (int j = (1); (j <= (i)); ++j) {
      possibilities.push_back({j, i});
      location[j][i] = (int)possibilities.size() - 1;
    }
  }
  cntPossibilities = possibilities.size();
  for (int i = (0); (i <= (cntPossibilities - 1)); ++i) {
    bitmask[i] = (1LL << cntPossibilities) - 1;
  }
  for (int i = (1); (i <= (n)); ++i) {
    deg[i] = e[i].size();
    sort(e[i].begin(), e[i].end());
    for (int j = (0); (j <= (deg[i] - 1)); ++j) {
      if (sumBitMask[e[i][j].x] & (1LL << location[j + 1][deg[i]])) {
        invalid[j + 1][deg[i]] = 1;
      }
      sumBitMask[e[i][j].x] |= (1LL << location[j + 1][deg[i]]);
    }
  }
  for (int i = (1); (i <= (n)); ++i) {
    for (int j = (0); (j <= (cntPossibilities - 1)); ++j)
      if (sumBitMask[i] & (1LL << j)) {
        bitmask[j] &= ~(sumBitMask[i] & ~(1LL << j));
      }
  }
  int res = cal(1, (1LL << cntPossibilities) - 1);
  cout << res;
}
