#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const long long N = 2038, mod = 1e9 + 7;
long long n, m, q, res, mx, f[N][2];
long long cnt, h[N], to[N << 1], nxt[N << 1], d[N << 1];
void add(long long u, long long v, long long w) {
  to[++cnt] = v, d[cnt] = w, nxt[cnt] = h[u], h[u] = cnt;
}
pair<long long, long long> t[N];
long long Pow(long long first, long long second) {
  long long tmp = 1;
  while (second) {
    if (second & 1) tmp = tmp * first % mod;
    first = first * first % mod, second >>= 1;
  }
  return tmp;
}
signed main() {
  read(n), read(m), read(q);
  for (long long i = 1, u, v, w; i <= m; ++i) {
    read(u), read(v), read(w);
    add(u, v, w), add(v, u, w);
    mx = max(mx, w);
  }
  for (long long i = 2; i <= n; ++i) f[i][0] = -1;
  for (long long k = 1; k <= m; ++k) {
    long long p = (k & 1), tmp = 0;
    for (long long i = 1; i <= n; ++i) {
      f[i][p] = -1;
      for (long long j = h[i]; j; j = nxt[j]) {
        if (f[to[j]][p ^ 1] >= 0)
          f[i][p] = max(f[i][p], f[to[j]][p ^ 1] + d[j]);
      }
      tmp = max(tmp, f[i][p]);
    }
    res = (res + tmp) % mod;
  }
  for (long long i = 1; i <= n; ++i) {
    t[i].second = f[i][m & 1];
    for (long long j = h[i]; j; j = nxt[j]) t[i].first = max(t[i].first, d[j]);
  }
  long long inv = Pow(2, mod - 2);
  sort(t + 1, t + n + 1);
  for (long long i = 1; i <= n; ++i) {
    long long l = 1, r = q - m;
    if (t[i].second == -1) continue;
    for (long long j = 1; j < i; ++j) {
      long long sx = t[i].first - t[j].first, sy = t[j].second - t[i].second;
      if (!sy) continue;
      long long t = ceil(1.0 * sy / sx);
      l = max(l, t);
    }
    for (long long j = i + 1; j <= n; ++j) {
      long long sx = t[i].first - t[j].first, sy = t[j].second - t[i].second;
      if (!sy) {
        r = 0;
        break;
      }
      long long t = ceil(1.0 * sy / sx) - 1;
      r = min(r, t);
    }
    if (l > r) continue;
    res =
        (res + (r - l + 1) * ((t[i].second * 2 + t[i].first * (l + r)) % mod) %
                   mod * inv % mod) %
        mod;
  }
  return printf("%lld\n", res), 0;
}
