#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 101;
int n, m, k;
vector<pair<int, int>> G[N];
vector<int> nodes[10][10];
bool bad[10][10];
unsigned long long lol[10][10];
unsigned long long ran() {
  unsigned long long res = 0;
  for (int i = 0; i <= 50; ++i) res = res * 2 + rand() % 2;
  return res;
}
unsigned long long w[N], all;
int out;
void brute(int x, unsigned long long hasz) {
  if (x == k + 1) {
    out += all == hasz;
    return;
  }
  for (int i = 1; i <= x; ++i) brute(x + 1, hasz + lol[x][i]);
}
int main() {
  srand(2137);
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    G[u].push_back(make_pair(w, v));
  }
  for (int i = 1; i <= n; ++i) {
    sort(G[i].begin(), G[i].end()), w[i] = ran();
    all += w[i];
    int sz = (int)G[i].size();
    for (int j = 0; j <= sz - 1; ++j) {
      nodes[sz][j + 1].push_back(G[i][j].second);
    }
  }
  for (int i = 1; i <= k; ++i)
    for (int j = 1; j <= k; ++j)
      for (auto x : nodes[i][j]) lol[i][j] += w[x];
  brute(1, 0);
  printf("%d\n", out);
  return 0;
}
