#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, mod = 1e9 + 7;
int bin[N], tot, n, m, K, i, j, k, in[N], f[11][11], ans;
vector<pair<int, int> > e[N];
void dfs(int x, int sum) {
  if (x == K + 1) {
    if (sum == tot) ans++;
    return;
  }
  for (int i = 1; i <= x; ++i) dfs(x + 1, (sum + f[x][i]) % mod);
}
int main() {
  for (scanf("%d%d%d", &n, &m, &K); m--;)
    scanf("%d%d%d", &i, &j, &k), in[i]++, e[i].push_back(pair<int, int>(k, j));
  for (bin[0] = 1, i = 1; i <= n; ++i)
    bin[i] = (bin[i - 1] << 1) % mod, tot = (tot + bin[i]) % mod;
  for (i = 1; i <= n; ++i)
    for (sort(e[i].begin(), e[i].end()), j = 0; j < in[i]; ++j)
      f[in[i]][j + 1] = (f[in[i]][j + 1] + bin[e[i][j].second]) % mod;
  dfs(1, 0);
  printf("%d\n", ans);
}
