#include <bits/stdc++.h>
using namespace std;
struct graph {
  long long u, v, w;
} G[2005];
long long dp[2005][2], b[2005];
int main() {
  long long i, n, j, k, t, m, q, ans;
  scanf("%lld%lld%lld", &n, &m, &q);
  for (i = 1; i <= m; i++) scanf("%lld%lld%lld", &G[i].u, &G[i].v, &G[i].w);
  for (i = 1; i <= n; i++) dp[i][0] = dp[i][1] = -0x3f3f3f3f;
  for (i = 1; i <= m; i++) b[i] = -0x3f3f3f3f;
  dp[1][0] = ans = 0;
  for (i = 1; i <= n - 1; i++) {
    k = 0;
    for (j = 1; j <= m; j++) {
      dp[G[j].u][i & 1] =
          max(dp[G[j].u][i & 1], dp[G[j].v][(i - 1) & 1] + G[j].w);
      dp[G[j].v][i & 1] =
          max(dp[G[j].v][i & 1], dp[G[j].u][(i - 1) & 1] + G[j].w);
      b[j] = max(b[j], max(dp[G[j].u][i & 1], dp[G[j].v][i & 1]) - i * G[j].w);
      k = max(k, max(dp[G[j].u][i & 1], dp[G[j].v][i & 1]));
    }
    ans = (ans + k) % (1000000007);
  }
  for (i = 1; i <= m; i++) {
    long long l = n, r = q;
    for (j = 1; j <= m; j++) {
      if (i == j) continue;
      long long s = G[i].w - G[j].w, e = b[j] - b[i];
      if (s > 0) l = max(l, e / s + 1);
      if (s < 0) r = min(r, e / s);
      if (!s) {
        if ((e > 0) || (!e && j < i)) {
          r = -1;
          break;
        }
      }
      if (l > r) break;
    }
    if (l <= r)
      ans = (ans +
             (l + r) * (r - l + 1) / 2 % (1000000007) * G[i].w % (1000000007) +
             (r - l + 1) * b[i] % (1000000007) + (1000000007)) %
            (1000000007);
  }
  printf("%lld\n", ans);
}
