#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
pair<long long, long long> operator+(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return make_pair((a.first + b.first) % mod, (a.second + b.second) % mod);
}
pair<long long, long long> operator+(pair<long long, long long> a,
                                     long long b) {
  return make_pair((a.first * b) % mod, (a.second * b) % mod);
}
pair<long long, long long> operator-(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return make_pair((a.first - b.first + mod) % mod,
                   (a.second - b.second + mod) % mod);
}
pair<long long, long long> operator*(pair<long long, long long> a,
                                     pair<long long, long long> b) {
  return make_pair((a.first * b.first) % mod, (a.second * b.second) % mod);
}
struct edge {
  int y, z;
  bool operator<(const edge &a) const { return z < a.z; }
} e[N];
int n, m, K, ans;
pair<long long, long long> bas = make_pair(131, 13331), h[N], tot, pre[15][15];
vector<edge> g[N];
void dfs(int x, pair<long long, long long> cur) {
  if (x == K + 1) {
    ans += (cur == tot);
    return;
  }
  for (int i = 0; i <= x - 1; i++) dfs(x + 1, cur + pre[x][i]);
}
int main() {
  cin >> n >> m >> K;
  h[0] = make_pair(1, 1);
  for (int i = 1; i <= n; i++) h[i] = h[i - 1] * bas, tot = tot + h[i];
  for (int i = 1; i <= m; i++) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    g[x].push_back((edge){y, z});
  }
  for (int i = 1; i <= n; i++) {
    sort(g[i].begin(), g[i].end());
    int sz = g[i].size();
    for (int j = 0; j <= sz - 1; j++) pre[sz][j] = pre[sz][j] + h[g[i][j].y];
  }
  dfs(1, make_pair(0, 0));
  printf("%d\n", ans);
  return 0;
}
