#include <bits/stdc++.h>
using namespace std;
const long long p = 1e9 + 7;
const long long maxn = 2e3 + 5;
vector<pair<long long, pair<long long, long long> > > b;
vector<pair<int32_t, pair<int32_t, int32_t> > > mom;
long long dp[maxn + 1][maxn + 1];
long long go(pair<long long, long long> a, pair<long long, long long> b) {
  long long u = b.second + a.second;
  long long v = b.first - a.first + 1;
  if (u % 2 == 0) {
    return (((u / 2) % p) * (v % p) - b.second) % p;
  } else {
    return (((v / 2) % p) * (u % p) - b.second) % p;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m, q;
  cin >> n >> m >> q;
  for (long long i = 0; i < m; ++i) {
    long long x, y, w;
    cin >> x >> y >> w;
    x--;
    y--;
    b.push_back({w, {x, y}});
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 0; j <= maxn; ++j) dp[i][j] = -1e18;
  }
  dp[0][0] = 0;
  for (long long i = 0; i < maxn; ++i) {
    for (long long j = 0; j < m; ++j) {
      pair<long long, pair<long long, long long> > z = b[j];
      long long x = z.second.first;
      long long y = z.second.second;
      long long w = z.first;
      dp[x][i + 1] = max(dp[x][i + 1], w + dp[y][i]);
      dp[y][i + 1] = max(dp[y][i + 1], w + dp[x][i]);
    }
  }
  long long sum = 0;
  for (long long i = 0; i <= min(maxn - 1, q); ++i) {
    long long ma = (-1e18);
    for (long long j = 0; j < n; ++j) {
      ma = max(ma, dp[j][i]);
    }
    sum += ma;
    sum %= p;
  }
  if (q < maxn) {
    cout << sum;
    return 0;
  }
  vector<pair<long long, long long> > a;
  for (long long i = 0; i < m; ++i) {
    long long x = b[i].second.first;
    long long y = b[i].second.second;
    long long o = max(dp[x][maxn - 1], dp[y][maxn - 1]);
    long long z = b[i].first;
    o -= (maxn - 1) * z;
    a.push_back({z, o});
  }
  for (long long i = 0; i < m; ++i) {
    mom.push_back({maxn, {i, i}});
  }
  for (long long i = 0; i < m; ++i) {
    mom.push_back({q + 1, {i, i}});
  }
  mom.push_back({1e9 + 5, {0, 0}});
  for (long long i = 0; i < m; ++i) {
    for (long long j = 0; j < i; ++j) {
      if ((a[i].first - a[j].first) * (a[i].second - a[j].second) >= 0) {
        continue;
      } else {
        long long h = (a[i].second - a[j].second) / (a[j].first - a[i].first);
        if (h >= (maxn - 1)) {
          mom.push_back({h, {i, j}});
          mom.push_back({h + 1, {i, j}});
        }
      }
    }
  }
  long long ans = (-1e18);
  long long l = 0;
  sort(mom.begin(), mom.end());
  vector<pair<long long, long long> > v(mom.size());
  for (long long i = 0; i < mom.size(); ++i) {
    if (mom[i].first < maxn) {
      continue;
    }
    long long x = mom[i].first;
    ans = a[l].first * x + a[l].second;
    long long l1 = mom[i].second.first;
    long long l2 = mom[i].second.second;
    if ((a[l1].first * x + a[l1].second) > ans) {
      ans = a[l1].first * x + a[l1].second;
      l = l1;
    }
    if ((a[l2].first * x + a[l2].second) > ans) {
      ans = a[l2].first * x + a[l2].second;
      l = l2;
    }
    if (v.empty() || v[v.size() - 1].first != x)
      v.push_back({x, ans});
    else {
      v[v.size() - 1].second = max(v[v.size() - 1].second, ans);
    }
  }
  mom.clear();
  for (long long i = 0; i < v.size(); ++i) {
    if (v[i].first < maxn) {
      continue;
    }
    if (v[i + 1].first == (1e9 + 5)) {
      cout << sum;
      return 0;
    } else {
      sum += go(v[i], v[i + 1]);
      sum %= p;
      sum += p;
      sum %= p;
    }
  }
  return 0;
}
