#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
const long long LLINF = 9223372036854775807LL;
const int maxn = 200010;
vector<pair<int, int> > a[maxn];
const int mod = 1000000009;
int hh[maxn];
int get_hash(int x) { return hh[x]; }
int th[10][10];
int target_hash = 0;
int result = 0;
int cvals[10];
void rec(int pos, int k, int cur_sum) {
  if (pos == k) {
    if (cur_sum == target_hash) result += 1;
    return;
  }
  for (int i = 0; i < pos + 1; ++i) {
    cvals[pos] = i;
    int new_sum = (cur_sum + th[pos + 1][i]) % mod;
    rec(pos + 1, k, new_sum);
  }
}
int main() {
  int n, m, k;
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 0; i < n + 1; ++i) {
    hh[i] = ((long long)i * i + rand()) % mod;
  }
  for (int i = 0; i < m; ++i) {
    int fr, to, w;
    scanf("%d%d%d", &fr, &to, &w);
    --fr, --to;
    a[fr].push_back(make_pair(w, to));
  }
  for (int i = 0; i < n; ++i) sort(a[i].begin(), a[i].end());
  for (int i = 1; i <= n; ++i) target_hash = (target_hash + get_hash(i)) % mod;
  for (int i = 0; i < n; ++i) {
    int cur_deg = int((a[i]).size());
    for (int j = 0; j < cur_deg; ++j) {
      int cur_h = get_hash(a[i][j].second + 1);
      th[cur_deg][j] = (th[cur_deg][j] + cur_h) % mod;
    }
  }
  rec(0, k, 0);
  cout << result << endl;
  return 0;
}
