#include <bits/stdc++.h>
using namespace std;
int n, m, k;
struct par {
  int y, z;
  par(int yy = 0, int zz = 0) : y(yy), z(zz) {}
  bool operator<(const par &B) const { return z < B.z; }
};
vector<par> e[200010];
int val[200010], S[10][10], ans = 0, aim = 1;
void dfs(int x, int now) {
  if (x > k) {
    if (now == aim) ans++;
    return;
  }
  for (int i = 1; i <= x; i++) dfs(x + 1, 1ll * now * S[x][i] % 1000000007);
}
int main() {
  scanf("%d %d %d", &n, &m, &k);
  for (int i = 1, x, y, z; i <= m; i++) {
    scanf("%d %d %d", &x, &y, &z);
    e[x].push_back(par(y, z));
  }
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= i; j++) S[i][j] = 1;
  for (int i = 1; i <= n; i++)
    val[i] = ((i << 3) + (i >> 2) * 173 + 23333333) % 99049904,
    aim = 1ll * aim * val[i] % 1000000007;
  for (int i = 1; i <= n; i++) {
    sort(e[i].begin(), e[i].end());
    for (int j = 0; j < e[i].size(); j++)
      S[e[i].size()][j + 1] =
          1ll * S[e[i].size()][j + 1] * val[e[i][j].y] % 1000000007;
  }
  dfs(1, 1);
  printf("%d", ans);
}
