#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const long long MOD = (long long)1e9 + 7;
const long long INF = (long long)1e18 + 5;
const long long is_query = -(1LL << 62);
struct Line {
  long long m, b;
  mutable function<const Line*()> succ;
  bool operator<(const Line& rhs) const {
    if (rhs.b != is_query) return m < rhs.m;
    const Line* s = succ();
    if (!s) return 0;
    long long x = rhs.m;
    return b - s->b < (s->m - m) * x;
  }
};
struct HullDynamic : public multiset<Line> {
  bool bad(iterator y) {
    auto z = next(y);
    if (y == begin()) {
      if (z == end()) return 0;
      return y->m == z->m && y->b <= z->b;
    }
    auto x = prev(y);
    if (z == end()) return y->m == x->m && y->b <= x->b;
    return 1.0 * (x->b - y->b) * (z->m - y->m) >=
           1.0 * (y->b - z->b) * (y->m - x->m);
  }
  void insert_line(long long m, long long b) {
    auto y = insert({m, b});
    y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
    if (bad(y)) {
      erase(y);
      return;
    }
    while (next(y) != end() && bad(next(y))) erase(next(y));
    while (y != begin() && bad(prev(y))) erase(prev(y));
  }
  long long eval(long long x) {
    auto l = *lower_bound((Line){x, is_query});
    return l.m * x + l.b;
  }
};
struct Edge {
  long long u, v, w;
};
long long n, m, range, dp[MAXN][MAXN];
vector<Edge> es;
long double intersect_x(Line l1, Line l2) {
  return (long double)(l2.b - l1.b) / (l1.m - l2.m);
}
long long arith(long long first, long long last) {
  return (first + last) * (last - first + 1) / 2 % MOD;
}
int main() {
  cin >> n >> m >> range;
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    es.push_back({u, v, w});
  }
  for (int i = 0; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = -INF;
    }
  }
  dp[0][1] = 0;
  for (int i = 1; i <= n; i++) {
    for (Edge e : es) {
      long long u = e.u, v = e.v, w = e.w;
      if (dp[i - 1][u] != -INF) dp[i][v] = max(dp[i][v], dp[i - 1][u] + w);
      if (dp[i - 1][v] != -INF) dp[i][u] = max(dp[i][u], dp[i - 1][v] + w);
    }
  }
  HullDynamic hull;
  for (Edge e : es) {
    long long slope = e.w, b = -INF;
    for (long long i = 0; i < n; i++) {
      if (dp[i][e.u] != -INF) {
        b = max(b, dp[i][e.u] - slope * i);
      }
      if (dp[i][e.v] != -INF) {
        b = max(b, dp[i][e.v] - slope * i);
      }
    }
    if (b != INF) {
      hull.insert_line(slope, b);
    }
  }
  long long ans = 0, l = n + 1, r = range;
  for (int i = 1; i <= min(n, range); i++) {
    long long maxv = -INF;
    for (int j = 1; j <= n; j++) {
      maxv = max(maxv, dp[i][j]);
    }
    assert(maxv != INF);
    ans += maxv;
  }
  ans %= MOD;
  long long pre = -INF;
  auto it = hull.begin();
  while (it != hull.end()) {
    auto nxt = next(it);
    long long cur = INF;
    if (nxt != hull.end()) {
      cur = (long long)intersect_x(*it, *nxt);
    }
    long long c = max(l, pre), d = min(r, cur);
    if (c <= d) {
      long long len = d - c + 1;
      ans = (ans + len * it->b + it->m * arith(c, d)) % MOD;
    }
    if (cur >= pre) {
      pre = cur + 1;
    }
    ++it;
  }
  ans = (ans + MOD) % MOD;
  cout << ans << '\n';
}
