#include <bits/stdc++.h>
using namespace std;
const int N = 4010;
const int MOD = (int)1e9 + 7;
int n, m, q, u, v, w;
long long f[N], a[N], b[N];
vector<pair<int, int> > g[N];
long long eval(int at, int mid) { return a[at] + f[at] * (mid - n - n - 1); }
bool check(int mid, int at) {
  long long t = eval(at, mid);
  for (int i = 0; i < n; i++) {
    long long r = eval(i, mid);
    if (r > t) {
      return false;
    }
    if (r == t && i < at) {
      return false;
    }
  }
  return true;
}
int main() {
  scanf("%d %d %d", &n, &m, &q);
  for (int i = 0; i < n; i++) {
    f[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d", &u, &v, &w);
    u--;
    v--;
    f[u] = max(f[u], 0LL + w);
    f[v] = max(f[v], 0LL + w);
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (int i = 0; i < n; i++) {
    a[i] = -1;
  }
  a[0] = 0;
  long long ans = 0;
  for (int i = 0; i <= n + n; i++) {
    for (int j = 0; j < n; j++) {
      b[j] = -1;
    }
    for (int j = 0; j < n; j++) {
      if (a[j] == -1) {
        continue;
      }
      for (int k = 0; k < g[j].size(); k++) {
        int o = g[j][k].first;
        long long p = a[j] + g[j][k].second;
        b[o] = max(b[o], p);
      }
    }
    if (i <= q) {
      ans += *max_element(a, a + n);
      ans %= MOD;
    }
    for (int j = 0; j < n; j++) {
      a[j] = b[j];
    }
  }
  int c = n + n + 1;
  while (c <= q) {
    int at = 0;
    long long t = 0;
    for (int i = 0; i < n; i++) {
      long long r = eval(i, c);
      if (r > t) {
        t = r;
        at = i;
      }
    }
    int low = c;
    int high = q;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (check(mid, at)) {
        low = mid + 1;
      } else {
        high = mid - 1;
      }
    }
    long long d = low - c;
    long long e = (d * (d - 1) / 2) % MOD;
    t %= MOD;
    ans += d * t % MOD;
    ans += e * f[at] % MOD;
    ans %= MOD;
    c = low;
  }
  printf("%lld\n", ans);
  return 0;
}
