#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmax(T& x, T y) {
  return x < y ? x = y, 1 : 0;
}
template <class T>
bool ckmin(T& x, T y) {
  return x > y ? x = y, 1 : 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
const int N = 2005;
const int inf = 0x3f3f3f3f;
inline void fmod(int& x) { x -= 1000000007, x += x >> 31 & 1000000007; }
int n, m, T, mxv, ans, dis[N][N];
pair<int, int> li[N];
int et, hed[N];
struct edge {
  int nx, to, vl;
} e[N << 1];
struct node {
  int x, y, z;
  node(int x_, int y_, int z_) { x = x_, y = y_, z = z_; }
};
vector<node> E;
void adde(int u, int v, int d) {
  e[++et].nx = hed[u], e[et].to = v, e[et].vl = d, hed[u] = et;
}
void Dij() {
  static bool vis[N][N];
  memset(vis, 0, sizeof(vis));
  memset(dis, -1, sizeof(dis));
  queue<pair<int, int> > q;
  q.push(make_pair(1, dis[1][0] = 0)), vis[1][0] = 1;
  while (!q.empty()) {
    pair<int, int> now = q.front();
    q.pop();
    int u = now.first, t = now.second;
    if (t == n) continue;
    for (int i = hed[u]; i; i = e[i].nx) {
      int v = e[i].to;
      if (ckmax(dis[v][t + 1], dis[u][t] + e[i].vl)) {
        if (!vis[v][t + 1]) q.push(make_pair(v, t + 1)), vis[v][t + 1] = 1;
      }
    }
  }
}
int calc(long long a1, long long d, long long n) {
  static const int iv2 = (1000000007 + 1) >> 1;
  return 1ll * (a1 + a1 + (n - 1) * d) % 1000000007 * n % 1000000007 * iv2 %
         1000000007;
}
signed main() {
  n = read(), m = read(), T = read();
  E.push_back(node(114, 514, 1919810));
  for (int i = 1, iend = m; i <= iend; ++i) {
    int x = read(), y = read(), z = read();
    adde(x, y, z), adde(y, x, z), ckmax(mxv, z), E.push_back(node(x, y, z));
  }
  Dij();
  for (int i = 1, iend = m; i <= iend; ++i)
    li[i].second = -2e9 - 5, li[i].first = E[i].z;
  for (int i = 1, iend = min(n, T); i <= iend; ++i) {
    for (int j = 1, jend = m; j <= jend; ++j) {
      int x = E[j].x, y = E[j].y, z = E[j].z;
      if (~dis[x][i]) ckmax(li[j].second, dis[x][i] - i * z);
      if (~dis[y][i]) ckmax(li[j].second, dis[y][i] - i * z);
    }
    long long res = 0;
    for (int j = 1, jend = m; j <= jend; ++j)
      ckmax(res, 1ll * li[j].first * i + li[j].second);
    fmod(ans += res % 1000000007);
  }
  for (int i = 1, iend = m; i <= iend; ++i) {
    int L = n + 1, R = T;
    for (int j = 1, jend = m; j <= jend; ++j) {
      if (i == j) continue;
      if (L > R) break;
      if (li[i].first == li[j].first) {
        if (li[i].second < li[j].second) {
          R = 114514, L = 1919810;
          break;
        } else if (li[i].second == li[j].second && i > j) {
          R = 114514, L = 1919810;
          break;
        } else
          continue;
      }
      if (li[i].first > li[j].first)
        ckmax(L,
              (li[j].second - li[i].second) / (li[i].first - li[j].first) + 1);
      else
        ckmin(R, (li[j].second - li[i].second) / (li[i].first - li[j].first));
    }
    if (L > R) continue;
    fmod(ans += calc(1ll * li[i].first * L % 1000000007 + li[i].second,
                     li[i].first, R - L + 1));
  }
  cout << ans << '\n';
  return 0;
}
