#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, mod = 1e9 + 7;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m, q;
  cin >> n >> m >> q;
  long long dis[n][m + 1];
  int idmx[m + 1];
  memset(idmx, 0, sizeof(idmx));
  vector<pair<int, int>> g[n];
  int mx[n];
  memset(mx, 0, sizeof(mx));
  vector<pair<int, pair<int, int>>> e;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
    e.push_back({w, {u, v}});
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j <= m; j++) dis[i][j] = -2 * mod;
  dis[0][0] = 0;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < n; j++)
      for (pair<int, int> u : g[j]) {
        dis[j][i] = max(dis[j][i], dis[u.first][i - 1] + u.second);
        if (dis[j][i] > dis[idmx[i]][i]) idmx[i] = j;
      }
  sort(e.begin(), e.end());
  set<pair<long long, int>> st;
  st.insert({0, 0});
  for (int i = 1; i <= m; i++) {
    if (idmx[i] != idmx[i - 1]) st.insert({i, idmx[i]});
  }
  for (auto x : e) {
    long long l = m, r = 1ll * mod * N;
    mx[x.second.first] = x.first;
    mx[x.second.second] = x.first;
    int idd = -1;
    while (r - l > 1) {
      long long mid = (l + r) / 2;
      auto it = st.upper_bound(make_pair(mid + 1, -1));
      it--;
      int id = (*it).second;
      long long val = (*it).first;
      long long mxx = 0;
      int id2 = x.second.first;
      int id3 = x.second.second;
      if (mid > m || dis[id2][mid] >= 0) {
        mxx = (mid <= m) ? dis[id2][mid]
                         : dis[id2][m] + 1ll * (mid - m) * mx[id2];
      } else
        id2 = -1;
      if (mid > m || dis[id3][mid] >= 0) {
        if (((mid <= m) ? dis[id3][mid]
                        : dis[id3][m] + 1ll * (mid - m) * mx[id3]) > mxx) {
          mxx = (mid <= m) ? dis[id3][mid]
                           : dis[id3][m] + 1ll * (mid - m) * mx[id3];
          id2 = id3;
        }
      }
      if (id2 == -1 ||
          ((val <= m) ? dis[id][val] + 1ll * (mid - val) * mx[id]
                      : dis[id][m] + 1ll * (mid - m) * mx[id]) > mxx)
        l = mid;
      else
        r = mid, idd = id2;
    }
    if (r != 1ll * mod * N) {
      auto it = st.lower_bound(make_pair(r, -1));
      while (it != st.end()) {
        auto it2 = it;
        it2++;
        st.erase(it);
        it = it2;
      }
      st.insert({r, idd});
    }
  }
  st.insert({q + 1, -1});
  long long cur = 0, lst = 0;
  long long ans = 0;
  for (auto x : st) {
    long long vv = x.first;
    vv %= mod;
    int id = x.second;
    long long val =
        (cur <= m) ? dis[lst][cur] : dis[lst][m] + 1ll * (cur - m) * mx[lst];
    val %= mod;
    ans += 1ll * val * (vv - cur) % mod;
    ans %= mod;
    ans += 1ll * (vv - cur - 1) * (vv - cur) / 2 % mod * mx[lst] % mod;
    ans %= mod;
    lst = id;
    cur = vv;
    if (x.first == q + 1) break;
  }
  cout << ans;
  return 0;
}
