#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const long long int infl = 1061109567;
const int nmax = 2e3 + 10;
vector<pair<long long int, int>> adj[nmax];
long long int memo[nmax][nmax];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  memset(memo, -1, sizeof(memo));
  int n, e;
  long long int q;
  cin >> n >> e >> q;
  for (int i = 0; i < e; i++) {
    int u, v;
    long long int w;
    cin >> u >> v >> w;
    adj[u].emplace_back(w, v);
    adj[v].emplace_back(w, u);
  }
  for (int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());
  memo[1][0] = 0;
  for (int len = 1; len <= n - 1; len++) {
    for (int u = 1; u <= n; u++) {
      for (auto p : adj[u]) {
        int v = p.second;
        if (memo[v][len - 1] == -1) continue;
        memo[u][len] = max(memo[u][len], memo[v][len - 1] + p.first);
      }
    }
  }
  long long int ans = 0;
  for (int len = 1; len <= n - 1; len++) {
    long long int best = 0;
    for (int u = 1; u <= n; u++) {
      best = max(best, memo[u][len]);
    }
    ans += best;
    ans %= mod;
  }
  q -= n - 1;
  q += 1;
  for (int u = 1; u <= n; u++) {
    long long int m = adj[u].back().first;
    long long int c = memo[u][n - 1];
    long long int l = 1, r = q;
    for (int v = 1; v <= n; v++) {
      if (u == v) continue;
      long long int m1 = adj[v].back().first;
      long long int c1 = memo[v][n - 1];
      if (m == m1) {
        if (c == c1 && v < u) l = 1, r = -1;
        if (c < c1) l = 1, r = -1;
      } else if (m < m1) {
        long long int r1 = (c - c1 + m1 - m - 1) / (m1 - m);
        r = min(r, r1);
      } else {
        long long int l1 = (c1 - c + m - m1 - 1) / (m - m1);
        l = max(l, l1);
      }
    }
    if (l > r) continue;
    ans += (r - l) * c % mod;
    ans += ((r - 1) * r / 2 - (l - 1) * l / 2) % mod * m % mod;
    ans %= mod;
  }
  ans = MOD(ans, mod);
  cout << ans << endl;
  return 0;
}
