#include <bits/stdc++.h>
using namespace std;
int n, m, k, d, i, f[10][10][10][10], a[105], ans, u, v, w, j, l, A, y[15][15];
struct str {
  int v, w;
};
vector<str> g[200005];
bitset<200005> p[10][10];
bool cmp(str a, str b) { return a.w < b.w; }
void dfs(int i) {
  if (i > A) {
    int j, k;
    for (j = 1; j <= A; ++j)
      for (k = j + 1; k <= A; ++k)
        if (f[j][a[j]][k][a[k]]) return;
    ++ans;
    return;
  }
  int j;
  for (j = 0; j < i; ++j)
    if (!y[i][j]) {
      a[i] = j;
      dfs(i + 1);
    }
}
int main() {
  scanf("%d %d %d", &n, &m, &A);
  for (i = 1; i <= m; ++i) {
    scanf("%d %d %d", &u, &v, &w);
    g[u].push_back((str){v, w});
  }
  for (i = 1; i <= n; ++i) {
    sort(g[i].begin(), g[i].end(), cmp);
    for (j = 0; j < g[i].size(); ++j) {
      if (p[g[i].size()][j][g[i][j].v]) y[g[i].size()][j] = 1;
      p[g[i].size()][j][g[i][j].v] = 1;
    }
  }
  for (i = 1; i <= A; ++i)
    for (j = 0; j < i; ++j)
      for (k = i + 1; k <= A; ++k)
        for (l = 0; l < k; ++l)
          if ((p[i][j] & p[k][l]).any()) f[i][j][k][l] = 1;
  dfs(1);
  cout << ans;
}
