#include <bits/stdc++.h>
using namespace std;
const long long N = 2005, mod = 1e9 + 7, inv2 = (mod + 1) / 2;
struct line {
  long long x, y;
} e[N];
long long dis[N][N], u[N], v[N], w[N];
long long calc(long long x, long long d, long long n) {
  return 1ll * (x + 1ll * (n - 1) * d + x) % mod * n % mod * inv2 % mod;
}
vector<pair<long long, long long>> E[N];
signed main() {
  ios::sync_with_stdio(false);
  long long n, m, T;
  cin >> n >> m >> T;
  for (long long i = 1; i <= m; ++i) {
    cin >> u[i] >> v[i] >> w[i];
    E[u[i]].push_back({v[i], w[i]});
    E[v[i]].push_back({u[i], w[i]});
  }
  memset(dis, -0x3f, sizeof(dis));
  dis[0][1] = 0;
  for (long long i = 0; i < n; ++i)
    for (long long u = 1; u <= n; ++u)
      for (auto p : E[u])
        dis[i + 1][p.first] = max(dis[i + 1][p.first], dis[i][u] + p.second);
  long long ans = 0;
  for (long long i = 1; i <= min(n, T); ++i) {
    long long tmp = 0;
    for (long long u = 1; u <= n; ++u) tmp = max(tmp, dis[i][u]);
    ans = (ans + tmp) % mod;
  }
  for (long long i = 1; i <= m; ++i) {
    e[i].x = w[i], e[i].y = -2e9;
    for (long long j = 0; j <= min(n, T); ++j) {
      if (dis[j][u[i]] >= 0) e[i].y = max(e[i].y, dis[j][u[i]] - j * w[i]);
      if (dis[j][v[i]] >= 0) e[i].y = max(e[i].y, dis[j][v[i]] - j * w[i]);
    }
  }
  for (long long i = 1; i <= m; ++i) {
    long long L = n + 1, R = T;
    for (long long j = 1; j <= m; ++j) {
      if (i == j) continue;
      if (L > R) break;
      if (e[i].x == e[j].x) {
        if (e[i].y < e[j].y) L = T + 1;
        if (e[i].y == e[j].y && i > j) L = T + 1;
        continue;
      }
      if (e[i].x > e[j].x)
        L = max(L, (e[j].y - e[i].y) / (e[i].x - e[j].x) + 1);
      else
        R = min(R, (e[j].y - e[i].y) / (e[i].x - e[j].x));
    }
    if (L <= R)
      ans = (ans +
             calc((1ll * e[i].x * L + mod + e[i].y) % mod, e[i].x, R - L + 1)) %
            mod;
  }
  cout << ans;
}
