#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 100;
struct edge {
  int nodo, cost, pos;
};
vector<edge> L[MAXN];
vector<pair<int, int>> arr[MAXN];
int N, M, K;
int dp[370000][10];
int contg = 0;
vector<int> ttt;
void fb(int pos) {
  if (pos == K + 1) {
    for (int i = 0; i < K; i++) {
      dp[contg][i] = ttt[i];
    }
    contg++;
    return;
  }
  for (int i = 1; i <= pos; i++) {
    ttt.push_back(i);
    fb(pos + 1);
    ttt.pop_back();
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> M >> K;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    L[a].push_back({b, c, -1});
  }
  for (int i = 1; i <= N; i++) {
    vector<pair<int, int>> temp;
    for (auto v : L[i]) {
      temp.push_back({v.cost, v.nodo});
    }
    L[i].clear();
    sort(temp.begin(), temp.end());
    for (int x = 0; x < temp.size(); x++) {
      L[i].push_back({temp[x].second, temp[x].first, x + 1});
    }
  }
  for (int i = 1; i <= N; i++) {
    for (auto x : L[i]) {
      arr[x.nodo].push_back({L[i].size(), x.pos});
    }
  }
  set<pair<pair<int, int>, pair<int, int>>> st;
  for (int i = 1; i <= N; i++) {
    sort(arr[i].begin(), arr[i].end());
    vector<pair<int, int>> vtt;
    int cont = 0;
    for (int x = 0; x < arr[i].size(); x++) {
      if (vtt.size() == 0) {
        vtt.push_back(arr[i][x]);
        cont = 1;
      } else {
        if (cont < 2) {
          if (vtt.back() == arr[i][x]) {
            cont++;
            vtt.push_back(arr[i][x]);
          } else {
            cont = 1;
            vtt.push_back(arr[i][x]);
          }
        } else {
          if (vtt.back() == arr[i][x]) {
          } else {
            cont = 1;
            vtt.push_back(arr[i][x]);
          }
        }
      }
    }
    arr[i] = vtt;
    for (int x = 0; x < arr[i].size(); x++) {
      for (int y = x + 1; y < arr[i].size(); y++) {
        pair<int, int> p1 = arr[i][x];
        pair<int, int> p2 = arr[i][y];
        if (p2 < p1) swap(p1, p2);
        st.insert({p1, p2});
      }
    }
  }
  vector<pair<pair<int, int>, pair<int, int>>> vect;
  for (auto x : st) {
    vect.push_back(x);
  }
  fb(1);
  int res = 0;
  for (int i = 0; i < contg; i++) {
    bool flag = true;
    for (auto xxx : vect) {
      if (dp[i][xxx.first.first - 1] == xxx.first.second &&
          dp[i][xxx.second.first - 1] == xxx.second.second)
        flag = false;
    }
    if (flag) res++;
  }
  cout << res << '\n';
  return 0;
}
