#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
long long power(long long x, long long y) {
  long long res = 1;
  while (y) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y / 2, x = (x * x) % 1000000007;
  }
  return res % 1000000007;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, q;
  cin >> n >> m >> q;
  vector<vector<pair<long long, long long> > > arr(n + 1);
  long long dp[n + 1][n + 1];
  for (long long i = 0; i < (m); ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    arr[u].emplace_back(make_pair(v, w));
    arr[v].emplace_back(make_pair(u, w));
  }
  for (long long i = 0; i < (n + 1); ++i)
    for (long long j = 0; j < (n + 1); ++j) dp[i][j] = -1e15;
  dp[1][0] = 0;
  for (long long i = 1; i <= n; ++i) {
    for (long long j = 1; j <= n; ++j) {
      for (auto v : arr[j]) {
        dp[v.first][i] = max(dp[v.first][i], dp[j][i - 1] + v.second);
      }
    }
  }
  long long len[n + 1];
  for (long long i = 0; i < (n + 1); ++i) len[i] = -1;
  for (long long i = 0; i < (n + 1); ++i) {
    for (long long j = 1; j <= n; ++j) {
      len[i] = max(len[i], dp[j][i]);
    }
  }
  long long ans = 0;
  for (long long i = 0; i < (min(n + 1, 1 + q)); ++i) {
    ans += len[i];
    ans %= 1000000007;
  }
  if (n >= q) {
    cout << ans << "\n";
    return 0;
  }
  vector<pair<long long, long long> > poss;
  for (long long i = 1; i <= n; ++i) {
    long long ma = 0;
    for (auto v : arr[i]) ma = max(ma, v.second);
    poss.emplace_back(make_pair(dp[i][n], ma));
  }
  vector<pair<pair<long long, long long>, long long> > range;
  for (long long i = 0; i < (n); ++i) {
    long long minl = 1;
    long long minr = q - n;
    bool pos = true;
    for (long long j = 0; j < (n); ++j) {
      if (poss[i].first == poss[j].first) {
        if (poss[i].second >= poss[j].second) {
          minl = max(minl, 1LL);
          minr = min(minr, q - n);
        } else {
          pos = false;
          break;
        }
      } else if (poss[i].first < poss[j].first) {
        if (poss[i].second > poss[j].second) {
          long long t = (poss[j].first - poss[i].first + poss[i].second -
                         poss[j].second - 1) /
                        (poss[i].second - poss[j].second);
          minl = max(minl, t);
        } else {
          pos = false;
          break;
        }
      } else {
        if (poss[i].second < poss[j].second) {
          long long t = (poss[j].first - poss[i].first) /
                        (poss[i].second - poss[j].second);
          minr = min(minr, t);
        }
      }
    }
    if (pos and minl <= minr)
      range.emplace_back(make_pair(make_pair(minl, minr), i));
  }
  sort(range.begin(), range.end());
  long long i = 0;
  for (auto v : range) {
    long long l = v.first.first;
    l = max(i + 1, l);
    long long r = v.first.second;
    r = min(r, q - n);
    if (l > r) continue;
    long long ind = v.second;
    long long p = r - l + 1;
    ans = ans + poss[ind].first * p % 1000000007;
    ans %= 1000000007;
    long long x = (r * (r + 1)) / 2;
    long long y = (l * (l - 1)) / 2;
    x -= y;
    x %= 1000000007;
    ans += (x * poss[ind].second % 1000000007);
    ans %= 1000000007;
    i = r;
    if (r == q - n) break;
  }
  cout << ans << "\n";
}
