#include <bits/stdc++.h>
inline int upd(const int x) { return x + (x >> 31 & 1000000007); }
inline void reduce(int& x) { x -= 1000000007, x += x >> 31 & 1000000007; }
inline void add(int& x, const int y) { x = upd((x + y) % 1000000007); }
const int inf = 0x3f3f3f3f;
int n, m, T, mxv, ans, dis[2005][2005];
std::pair<int, int> li[2005];
int et, hed[2005];
struct edge {
  int nx, to, vl;
} e[2005 << 1];
struct node {
  int x, y, z;
  node(int x_, int y_, int z_) { x = x_, y = y_, z = z_; }
};
std::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[2005][2005];
  memset(vis, 0, sizeof(vis));
  memset(dis, -1, sizeof(dis));
  std::queue<std::pair<int, int> > q;
  q.push(std::make_pair(1, dis[1][0] = 0)), vis[1][0] = 1;
  while (!q.empty()) {
    std::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 (dis[v][t + 1] < dis[u][t] + e[i].vl) {
        dis[v][t + 1] = dis[u][t] + e[i].vl;
        if (!vis[v][t + 1]) q.push(std::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() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0), std::cout.tie(0);
  std::cin >> n >> m >> T;
  E.push_back(node(114, 514, 1919810));
  for (int i = 1, iend = m; i <= iend; ++i) {
    int x, y, z;
    std::cin >> x >> y >> z;
    adde(x, y, z), adde(y, x, z), E.push_back(node(x, y, z)),
        mxv = std::max(mxv, 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 = std::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]) li[j].second = std::max(dis[x][i] - i * z, li[j].second);
      if (~dis[y][i]) li[j].second = std::max(dis[y][i] - i * z, li[j].second);
    }
    long long res = 0;
    for (int j = 1, jend = m; j <= jend; ++j)
      res = std::max(res, 1ll * li[j].first * i + li[j].second);
    reduce(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)
        L = std::max(
            L, (li[j].second - li[i].second) / (li[i].first - li[j].first) + 1);
      else
        R = std::min(
            R, (li[j].second - li[i].second) / (li[i].first - li[j].first));
    }
    if (L > R) continue;
    reduce(ans += calc(1ll * li[i].first * L % 1000000007 + li[i].second,
                       li[i].first, R - L + 1));
  }
  std::cout << ans << '\n';
  return 0;
}
