#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct nod {
  int to, len;
  nod() {}
  nod(int a1, int a2) { to = a1, len = a2; }
};
vector<nod> edge[200005];
bool cmp(nod i, nod j) { return i.len < j.len; }
int a[200005][105], vis[105][105], tmp[10], ans;
void dfs(int p) {
  if (p == k + 1) {
    for (int i = 1; i <= k; i++)
      for (int j = i; j <= k; j++)
        if (vis[i * 10 + tmp[i]][j * 10 + tmp[j]] == 1 ||
            vis[j * 10 + tmp[j]][i * 10 + tmp[i]] == 1)
          return;
    ans++;
    return;
  }
  for (int i = 1; i <= p; i++) tmp[p] = i, dfs(p + 1);
}
signed main() {
  ios::sync_with_stdio(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge[u].push_back(nod(v, w));
  }
  for (int i = 1; i <= n; i++) sort(edge[i].begin(), edge[i].end(), cmp);
  for (int i = 1; i <= n; i++) {
    int siz = edge[i].size();
    for (int j = 1; j <= siz; j++) {
      nod tt = edge[i][j - 1];
      for (int k = 1; k <= 100; k++) {
        if (a[tt.to][k]) {
          vis[k][siz * 10 + j] = vis[siz * 10 + j][k] = 1;
        }
      }
      a[tt.to][siz * 10 + j] = 1;
    }
  }
  dfs(1);
  cout << ans << endl;
}
