#include <bits/stdc++.h>
using namespace std;
namespace Base {
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const long long infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
template <typename T>
void read(T &x) {
  x = 0;
  int fh = 1;
  double num = 1.0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  if (ch == '.') {
    ch = getchar();
    while (isdigit(ch)) {
      num /= 10;
      x = x + num * (ch - '0');
      ch = getchar();
    }
  }
  x = x * fh;
}
template <typename T>
void chmax(T &x, T y) {
  x = x < y ? y : x;
}
template <typename T>
void chmin(T &x, T y) {
  x = x > y ? y : x;
}
}  // namespace Base
using namespace Base;
const int N = 2020, P = 1e9 + 7;
int n, m, q, u[N], v[N], w[N], dp[N][N], id[N], r[N], stk[N], stb[N];
vector<int> e[N], ew[N];
bool cmp(int x, int y) { return w[x] < w[y]; }
int check(int k1, int b1, int k2, int b2) {
  if (b1 >= b2) return 0;
  if (k1 == k2) return inf;
  return (b2 - b1) / (k1 - k2) + ((b2 - b1) % (k1 - k2) != 0);
}
int main() {
  read(n);
  read(m);
  read(q);
  for (int i = 1; i <= m; i++) {
    read(u[i]);
    read(v[i]);
    read(w[i]);
    e[u[i]].push_back(v[i]);
    ew[u[i]].push_back(w[i]);
    e[v[i]].push_back(u[i]);
    ew[v[i]].push_back(w[i]);
  }
  memset(dp, -1, sizeof(dp));
  dp[0][1] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dp[i][j] == -1) continue;
      for (unsigned k = 0; k < e[j].size(); k++)
        chmax(dp[i + 1][e[j][k]], dp[i][j] + ew[j][k]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= min(q, n); i++) {
    int tmp = 0;
    for (int j = 1; j <= n; j++) chmax(tmp, dp[i][j]);
    ans = (1ll * ans + tmp) % P;
  }
  if (q <= n) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 1; i <= m; i++) id[i] = i;
  sort(id + 1, id + m + 1, cmp);
  int top = 0;
  r[0] = n;
  for (int i = 1; i <= m; i++) {
    int x = id[i], k = w[x], b = -inf;
    for (int j = 0; j <= n; j++) {
      int num = max(dp[j][u[x]], dp[j][v[x]]);
      if (num == -1) continue;
      chmax(b, num - j * k);
    }
    if (b == -inf) continue;
    while (top > 0 && check(k, b, stk[top], stb[top]) <= r[top - 1]) top--;
    if (top > 0) r[top] = check(k, b, stk[top], stb[top]) - 1;
    if (r[top] != inf - 1) stk[++top] = k, stb[top] = b;
  }
  r[top] = q;
  for (int i = 1; i <= top; i++) {
    long long s = ((1ll * stk[i] * (r[i - 1] + 1) + stb[i]) +
                   (1ll * stk[i] * r[i] + stb[i])),
              m = r[i] - r[i - 1];
    if (s % 2 == 0)
      s /= 2;
    else
      m /= 2;
    ans = (ans + s % P * m % P) % P;
  }
  cout << ans << endl;
  return 0;
}
