#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-8;
const int mod = 1e9 + 7;
const int maxn = 1e6 + 100;
const int N = 2e5 + 100;
const int M = 500 + 10;
const long long mm = (1LL << 32);
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= c == '-';
  for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  T y = 1;
  int len = 1;
  for (; y <= x / 10; y *= 10) ++len;
  for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
long long qpow(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return ans;
}
vector<pair<int, int> > g[N], in[N];
bool bad[12][12][12][12];
int n, m, k, ans;
int c[12];
void dfs(int i) {
  for (int j = 1; j <= i; ++j) {
    c[i] = j;
    bool flag = 0;
    for (int z = 1; z <= i; ++z) flag |= bad[z][c[z]][i][j];
    if (!flag) {
      if (i == k)
        ans++;
      else
        dfs(i + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k;
  for (int i = 1; i <= m; ++i) {
    int x, y, w;
    cin >> x >> y >> w;
    g[x].push_back({w, y});
  }
  for (int i = 1; i <= n; ++i) sort(g[i].begin(), g[i].end());
  for (int i = 1; i <= n; ++i) {
    int sz = g[i].size();
    for (int j = 0; j < sz; ++j) {
      int v = g[i][j].second;
      in[v].push_back({sz, j + 1});
    }
  }
  for (int i = 1; i <= n; ++i) sort(in[i].begin(), in[i].end());
  pair<int, int> p1, p2;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < ((int)in[i].size()); ++j) {
      p1 = in[i][j];
      if (j && p1 == in[i][j - 1]) continue;
      for (int k = j + 1; k < ((int)in[i].size()); ++k) {
        p2 = in[i][k];
        bad[p1.first][p1.second][p2.first][p2.second] = 1;
        bad[p2.first][p2.second][p1.first][p1.second] = 1;
      }
    }
  }
  dfs(1);
  cout << ans << endl;
  return 0;
}
