#include <bits/stdc++.h>
const int kN = 200000 + 5;
int n, m, k;
std::bitset<kN> in[10][10];
int cnt[10][10];
bool collision[10][10][10][10];
std::vector<std::pair<int, int>> edges[kN];
int selected[10];
bool ok(int i, int j) {
  for (int k = 1; k < i; ++k) {
    if (collision[i][j][k][selected[k]]) return false;
  }
  return true;
}
int search(int at, int num) {
  if (at == k + 1) {
    return num == n;
  }
  int ret = 0;
  for (int i = 1; i <= at; ++i) {
    if (ok(at, i)) {
      selected[at] = i;
      ret += search(at + 1, num + cnt[at][i]);
    }
  }
  return ret;
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < m; ++i) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a;
    --b;
    edges[a].emplace_back(c, b);
  }
  for (int u = 0; u < n; ++u) {
    std::sort(edges[u].begin(), edges[u].end());
    int s = edges[u].size();
    for (int i = 0; i < s; ++i) {
      in[s][i + 1].set(edges[u][i].second);
    }
  }
  for (int i = 1; i <= 9; ++i)
    for (int j = 1; j <= i; ++j) cnt[i][j] = in[i][j].count();
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= i; ++j) {
      for (int k = 1; k <= 9; ++k) {
        for (int r = 1; r <= k; ++r) {
          if ((in[i][j] & in[k][r]).count()) collision[i][j][k][r] = true;
        }
      }
    }
  }
  printf("%d\n", search(1, 0));
}
