#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
bool dot(const pair<long long, long long>& a,
         const pair<long long, long long>& b,
         const pair<long long, long long>& c) {
  return (a.first - c.first) * (b.second - c.second) >=
         (a.second - c.second) * (b.first - c.first);
}
struct ChtMax {
  const long long MX = 6e18;
  vector<pair<long long, long long> > hull;
  vector<pair<long long, long long> > qu;
  void add(pair<long long, long long> a) {
    while (hull.size() >= 2 && dot(hull.back(), a, hull[hull.size() - 2]))
      hull.pop_back();
    hull.push_back(a);
  }
  void lazyAdd(pair<long long, long long> a) { qu.push_back(a); }
  void lazyUpdate() {
    sort(qu.begin(), qu.end());
    qu.erase(unique(qu.begin(), qu.end()), qu.end());
    for (auto a : qu) {
      add(a);
    }
  }
  long long query(long long x) {
    if (hull.size() == 0) return MX;
    int l = 1, h = hull.size() - 1, m;
    long long best = hull[0].first * x + hull[0].second;
    while (l <= h) {
      m = (l + h) / 2;
      long long cm = hull[m].first * x + hull[m].second;
      long long cmm = hull[m - 1].first * x + hull[m - 1].second;
      best = max(best, max(cm, cmm));
      if (cmm < cm)
        l = m + 1;
      else
        h = m - 1;
    }
    return best;
  }
  long long getUpperboundForLine(int i) {
    if (i + 1 >= (int)hull.size()) return MX;
    if (hull[i].first == hull[i + 1].first) return -MX;
    return (hull[i + 1].second - hull[i].second) /
               (hull[i].first - hull[i + 1].first) +
           1;
  }
  long long getLowerboundForLine(int i) {
    if (i == 0) return -MX;
    long long x = getUpperboundForLine(i - 1);
    if (x == -MX) return MX;
    return x;
  }
  void removeVertical() {
    while (hull.size() > 1 && hull.back().first == hull[hull.size() - 2].first)
      hull.pop_back();
    reverse(hull.begin(), hull.end());
    while (hull.size() > 1 && hull.back().first == hull[hull.size() - 2].first)
      hull.pop_back();
    reverse(hull.begin(), hull.end());
  }
};
vector<vector<pair<int, int> > > graf;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  long long q;
  cin >> n >> m >> q;
  q++;
  graf.resize(n);
  vector<pair<pair<int, int>, int> > edg(2 * m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    graf[a - 1].push_back({b - 1, c});
    graf[b - 1].push_back({a - 1, c});
    edg[2 * i] = {{a - 1, b - 1}, c};
    edg[2 * i + 1] = {{b - 1, a - 1}, c};
  }
  vector<vector<long long> > dp(min((int)q, m + 6), vector<long long>(n, -1));
  dp[0][0] = 0;
  long long res = 0;
  ChtMax cht;
  for (int l = 1; l < dp.size(); l++) {
    int ct = 0;
    long long resi = 0;
    for (auto a : edg) {
      ct++;
      if (dp[l - 1][a.first.first] == -1) continue;
      dp[l][a.first.second] =
          max(dp[l][a.first.second], dp[l - 1][a.first.first] + a.second);
      resi = max(resi, dp[l][a.first.second]);
      cht.lazyAdd({a.second, dp[l][a.first.second] - a.second * l});
    }
    res = (res + resi) % MOD;
  }
  cht.lazyUpdate();
  cht.removeVertical();
  for (int i = 0; i < cht.hull.size(); i++) {
    long long low = max((long long)dp.size(), cht.getLowerboundForLine(i));
    long long high = min(q, cht.getUpperboundForLine(i));
    if (low >= high) continue;
    long long w1 = (cht.hull[i].first * low + cht.hull[i].second) % MOD *
                   (high - low) % MOD;
    long long w2 =
        ((high - low) * (high - low - 1) / 2) % MOD * cht.hull[i].first % MOD;
    res = (res + w1 + w2) % MOD;
  }
  cout << res << "\n";
}
