#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
int n, m, k, c[10], res;
int kt[10][10][10][10];
vector<int> b[10];
set<int> ver[10][10];
vector<pair<int, int> > a[N];
void Try(int d) {
  if (d == k + 1) {
    int check = 1;
    for (int i = 1; i <= k; i++)
      for (int j = i + 1; j <= k; j++)
        if (!kt[i][c[i]][j][c[j]]) i = k + 1, j = k + 1, check = 0;
    for (int i = 1; i <= k; i++)
      if (*ver[i][c[i]].begin() == -1) check = 0, i = k + 1;
    if (check) res++;
    return;
  }
  for (int i = 1; i <= d; i++) {
    c[d] = i;
    Try(d + 1);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    a[u].push_back(make_pair(w, v));
  }
  for (int i = 1; i <= n; i++) {
    b[a[i].size()].push_back(i);
    sort(a[i].begin(), a[i].end());
  }
  for (int i = 1; i <= k; i++) {
    for (int j = 1; j <= i; j++) {
      for (int u : b[i]) {
        if (ver[i][j].find(a[u][j - 1].second) != ver[i][j].end()) {
          ver[i][j].clear();
          ver[i][j].insert(-1);
          break;
        }
        ver[i][j].insert(a[u][j - 1].second);
      }
    }
  }
  for (int i1 = 1; i1 <= k; i1++) {
    for (int j1 = 1; j1 <= i1; j1++) {
      if (*ver[i1][j1].begin() == -1) continue;
      for (int i2 = i1 + 1; i2 <= k; i2++) {
        for (int j2 = 1; j2 <= i2; j2++) {
          if (*ver[i2][j2].begin() == -1) continue;
          for (int u : ver[i2][j2]) {
            if (ver[i1][j1].find(u) != ver[i1][j1].end()) {
              kt[i1][j1][i2][j2] = 1;
              break;
            }
          }
          kt[i1][j1][i2][j2] = 1 - kt[i1][j1][i2][j2];
        }
      }
    }
  }
  Try(1);
  cout << res;
}
