#include <bits/stdc++.h>
using namespace std;
const long long L = 4000;
struct line {
  long long m, c;
  long long eval(long long x) { return m * x + c; }
  long double intersectX(line l) { return (long double)(c - l.c) / (l.m - m); }
};
const long long MOD = 1e9 + 7;
const long long N = 2004;
vector<pair<long long, long long> > g[N];
vector<long long> cur(N), nex(N);
const long long inf = 1e18;
vector<pair<long long, long long> > go;
long long calc(line ln, long long x1, long long x2) {
  ln.m %= MOD;
  ln.c %= MOD;
  long long fix = (ln.c + (ln.m * x1));
  fix %= MOD;
  long long res = (fix * (x2 - x1 + 1));
  res %= MOD;
  long long s1 = (x2 - x1);
  long long s2 = (s1 * (s1 + 1)) / 2;
  s2 %= MOD;
  res += (ln.m * s2);
  res %= MOD;
  return res;
}
void solve() {
  long long n, m, q;
  cin >> n >> m >> q;
  long long u, v, w;
  for (long long i = 0; i < m; i++) {
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (long long i = 2; i <= n; i++) cur[i] = -inf;
  cur[1] = 0;
  long long res = 0;
  for (long long i = 1; i <= min(q, L); i++) {
    for (long long j = 1; j <= n; j++) nex[j] = -inf;
    for (long long j = 1; j <= n; j++)
      for (auto x : g[j]) nex[x.first] = max(nex[x.first], cur[j] + x.second);
    swap(cur, nex);
    res += *max_element(cur.begin(), cur.end());
    res %= MOD;
  }
  if (q > L) {
    deque<line> dq;
    dq.push_front({0, 0});
    for (long long i = 1; i <= n; i++)
      for (auto x : g[i]) go.push_back({x.second, cur[i] - (x.second * L)});
    sort(go.begin(), go.end());
    auto go2 = go;
    go.clear();
    for (auto x : go2) {
      if (go.empty())
        go.push_back(x);
      else if (go.back().first == x.first) {
        go.back() = x;
      } else
        go.push_back(x);
    }
    for (auto x : go) {
      line cur = {x.first, x.second};
      while (dq.size() >= 2 && cur.intersectX(dq[0]) <= dq[0].intersectX(dq[1]))
        dq.pop_front();
      dq.push_front(cur);
    }
    long long st = L + 1;
    while (st <= q && !dq.empty()) {
      auto z1 = dq.back();
      dq.pop_back();
      if (dq.empty()) {
        res += calc(z1, st, q);
        res %= MOD;
        break;
      }
      auto z2 = dq.back();
      if (z1.m == z2.m) continue;
      double interX = (z1.c - z2.c) / (z2.m - z1.m);
      long long R = min(q, (long long)floor(interX));
      if (R >= st) {
        res += calc(z1, st, R);
        res %= MOD;
        st = R + 1;
      }
    }
  }
  cout << res;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
}
