#include <bits/stdc++.h>
using namespace std;
int n, m, k, first, second, z, ans, a[10], b[10][10][10][10];
vector<pair<int, int> > t[10][10], temp[200005];
vector<pair<int, int> > g[200005];
vector<int> h[200005];
void Gen(int p) {
  if (p == k + 1) {
    for (int i = 1; i <= k; i++) {
      for (int j = i; j <= k; j++) {
        if (b[i][a[i]][j][a[j]]) return;
      }
    }
    ans++;
    return;
  }
  for (int i = 1; i <= p; i++) {
    a[p] = i;
    Gen(p + 1);
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie();
  cout.tie();
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    cin >> first >> second >> z;
    g[first].push_back({z, second});
    h[second].push_back(first);
  }
  for (int i = 1; i <= n; i++) sort((g[i]).begin(), (g[i]).end());
  for (int i = 1; i <= n; i++) {
    for (int k = 0; k < g[i].size(); k++) {
      temp[g[i][k].second].push_back({g[i].size(), k + 1});
    }
  }
  for (int i = 1; i <= n; i++) {
    for (pair<int, int> j : temp[i]) b[j.first][j.second][j.first][j.second]++;
    temp[i].erase(unique((temp[i]).begin(), (temp[i]).end()), temp[i].end());
    for (pair<int, int> j : temp[i])
      b[j.first][j.second][j.first][j.second] -= 2;
    for (pair<int, int> j : temp[i]) {
      for (pair<int, int> k : temp[i]) {
        b[j.first][j.second][k.first][k.second]++;
      }
    }
  }
  Gen(1);
  cout << ans;
}
