#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000 * 1000 * 1000 + 7;
long long mod(long long n) {
  n %= MOD;
  if (n < 0)
    return n + MOD;
  else
    return n;
}
long long fp(long long a, long long p) {
  long long ans = 1, c = a;
  for (long long i = 0; (1ll << i) <= p; ++i) {
    if ((p >> i) & 1) ans = mod(ans * c);
    c = mod(c * c);
  }
  return ans;
}
long long dv(long long a, long long b) { return mod(a * fp(b, MOD - 2)); }
const long long N = 2007, T = 10000, INF = 1e18;
vector<pair<long long, long long> > g[N];
long long dp1[N], dp2[N];
void rel(long long &a, long long b) { a = max(a, b); }
void add(long long &a, long long b) { a = mod(a + b); }
long long inv2;
long long sum(long long n) { return mod(mod(n * (n + 1)) * inv2); }
long long getsum(long long second, long long d, long long k) {
  return mod(second * k + sum(k) * d);
}
struct Line {
  long long k, b;
  Line() : k(), b() {}
  Line(long long _k, long long _b) : k(_k), b(_b) {}
  long long getVal(long long x) {
    if (abs(k) > 1000 * 1000) {
      cout << "t1" << endl;
      exit(0);
    }
    if (abs(x) > 1000 * 1000 * 1000) {
      cout << "t2" << endl;
      exit(0);
    }
    return k * x + b;
  }
};
struct Hull {
  vector<Line> lines;
  vector<long long> borders;
  Hull() : lines(), borders() {}
  void addLine(Line L) {
    while (!lines.empty()) {
      if (lines.back().getVal(borders.back()) >= L.getVal(borders.back())) {
        lines.pop_back();
        borders.pop_back();
      } else
        break;
    }
    if (lines.empty()) {
      lines.push_back(L);
      borders.push_back(0LL);
      return;
    }
    if (lines.back().k <= L.k) return;
    long long x = (L.b - lines.back().b + lines.back().k - L.k - 1) /
                  (lines.back().k - L.k);
    lines.push_back(L);
    borders.push_back(x);
  }
  long long who(long long x) {
    long long pos =
        upper_bound(borders.begin(), borders.end(), x) - borders.begin();
    if (pos == 0) throw;
    pos--;
    return pos;
  }
  long long getMinVal(long long x) {
    long long pos =
        upper_bound(borders.begin(), borders.end(), x) - borders.begin();
    if (pos == 0) throw;
    pos--;
    return lines[pos].getVal(x);
  }
} d;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  inv2 = fp(2, MOD - 2);
  long long n, m, q;
  cin >> n >> m >> q;
  for (long long i = 0; i < m; ++i) {
    long long u, v, w;
    cin >> u >> v >> w;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  for (long long i = 2; i <= n; ++i) dp1[i] = -INF;
  long long ans = 0;
  for (long long len = 1; len <= T; ++len) {
    for (long long i = 1; i <= n; ++i) dp2[i] = -INF;
    for (long long u = 1; u <= n; ++u) {
      if (dp1[u] == -INF) continue;
      for (auto e : g[u]) {
        long long v = e.first, c = e.second;
        dp2[v] = max(dp2[v], dp1[u] + c);
      }
    }
    for (long long i = 1; i <= n; ++i) dp1[i] = dp2[i];
    if (len <= q) {
      long long mx = 0;
      for (long long i = 1; i <= n; ++i) rel(mx, dp1[i]);
      add(ans, mx);
    }
  }
  vector<Line> ar;
  for (long long u = 1; u <= n; ++u) {
    if (dp1[u] == -INF) continue;
    long long mx = 0;
    for (auto e : g[u]) {
      mx = max(mx, e.second);
    }
    ar.push_back(Line(-mx, -(dp1[u] - T * mx)));
  }
  auto comp = [](Line a, Line b) { return a.k > b.k; };
  sort(ar.begin(), ar.end(), comp);
  for (auto e : ar) {
    d.addLine(e);
  }
  if (T < q) {
    long long ptr = T + 1;
    while (ptr <= q) {
      long long l = ptr;
      long long r = q + 1;
      while (l < r - 1) {
        long long m = (l + r) >> 1;
        if (d.who(m) == d.who(l))
          l = m;
        else
          r = m;
      }
      auto ln = d.lines[d.who(l)];
      add(ans, -ln.b * (l - ptr + 1));
      add(ans, -mod(sum(l) - sum(ptr - 1)) * ln.k);
      ptr = r;
    }
  }
  cout << ans << '\n';
}
