#include <bits/stdc++.h>
using namespace std;
const int N = 2010, mod = 1e9 + 7, inf = 0x3f3f3f3f;
long long dp[N][N];
long long bit[N];
int u[N], v[N], w[N];
int n, m, q;
int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < m; i++) scanf("%d%d%d", &u[i], &v[i], &w[i]);
  memset(dp, -inf, sizeof dp);
  memset(bit, -inf, sizeof bit);
  int ans = 0;
  dp[0][1] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i][u[j]] = max(dp[i - 1][v[j]] + w[j], dp[i][u[j]]);
      dp[i][v[j]] = max(dp[i - 1][u[j]] + w[j], dp[i][v[j]]);
    }
    for (int j = 0; j < m; j++)
      bit[j] = max(bit[j], max(dp[i][v[j]], dp[i][u[j]]) - (long long)i * w[j]);
    long long res = 0;
    for (int j = 1; j <= n; j++) res = max(dp[i][j], res);
    ans = (ans + res) % mod;
  }
  for (int i = 0; i < m; i++) {
    int l = n, r = q;
    for (int j = 0; l <= r && j < m; j++)
      if (i != j) {
        int k = w[i] - w[j];
        int b = bit[j] - bit[i];
        if (k > 0)
          l = max(l, b / k + 1);
        else if (k < 0)
          r = min(r, b / k);
        else {
          if (!(b < 0 || (b == 0 && j < i))) r = -1;
        }
      }
    if (l <= r) {
      ans = ((long long)ans + (long long)(r - l + 1) * bit[i] % mod +
             (long long)(l + r) * (r - l + 1) / 2 % mod * w[i] % mod) %
            mod;
    }
    if (ans < 0) ans = (ans + mod);
  }
  printf("%d\n", ans);
  return 0;
}
