#include <bits/stdc++.h>
using namespace std;
template <class T = int>
T read() {
  T x = 0;
  char ch = 0;
  bool f = false;
  while (!isdigit(ch)) f |= (ch = getchar()) == '-';
  for (; isdigit(ch); ch = getchar()) x = x * 10 + (ch ^ '0');
  return f ? -x : x;
}
struct E {
  int v, w;
};
bool operator<(E a, E b) { return a.w < b.w; }
const int N = 200200;
vector<E> es[N];
const int K = 12;
bool ban[K * K][K * K];
vector<int> ins[N];
int main() {
  int n = read(), m = read();
  int k = read();
  for (int i = (int)(1); i <= (int)(m); i++) {
    int u = read(), v = read(), w = read();
    es[u].push_back({v, w});
  }
  for (int i = (int)(1); i <= (int)(n); i++) sort(es[i].begin(), es[i].end());
  for (int i = (int)(1); i <= (int)(n); i++) {
    int s = es[i].size();
    for (int j = 0; j < (int)(s); j++) {
      int v = es[i][j].v;
      ins[v].push_back(s * K + j + 1);
    }
  }
  for (int i = (int)(1); i <= (int)(n); i++) {
    int s = ins[i].size();
    map<int, int> mp;
    for (int j = 0; j < (int)(s); j++) mp[ins[i][j]]++;
    for (auto p1 : mp)
      for (auto p2 : mp) {
        if (p1.first != p2.first || p1.second >= 2) {
          ban[p1.first][p2.first] = true;
        }
      }
  }
  int a[K];
  int ans = 0;
  for (a[1] = 1; a[1] <= (1 <= k ? 1 : 1); a[1]++)
    for (a[2] = 1; a[2] <= (2 <= k ? 2 : 1); a[2]++)
      for (a[3] = 1; a[3] <= (3 <= k ? 3 : 1); a[3]++)
        for (a[4] = 1; a[4] <= (4 <= k ? 4 : 1); a[4]++)
          for (a[5] = 1; a[5] <= (5 <= k ? 5 : 1); a[5]++)
            for (a[6] = 1; a[6] <= (6 <= k ? 6 : 1); a[6]++)
              for (a[7] = 1; a[7] <= (7 <= k ? 7 : 1); a[7]++)
                for (a[8] = 1; a[8] <= (8 <= k ? 8 : 1); a[8]++)
                  for (a[9] = 1; a[9] <= (9 <= k ? 9 : 1); a[9]++) {
                    for (int i = (int)(1); i <= (int)(9); i++)
                      for (int j = (int)(1); j <= (int)(9); j++)
                        if (ban[i * K + a[i]][j * K + a[j]]) goto qaq;
                    ans++;
                  qaq:;
                  }
  printf("%d\n", ans);
  return 0;
}
