#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int inv2 = 500000004;
vector<pair<int, int> > mp[2005];
int ans[2005], dis[2005][2005];
queue<pair<int, int> > q;
int maxw[2005];
pair<int, int> p[2005];
int n, m, qq, u, v, w, now, step, last, t, aa, an, anss;
bool check(int x, int id) {
  long long maxx = 0;
  for (int i = 1; i <= n; i++)
    maxx = max(maxx, 1LL * p[i].first * (x - m) + p[i].second);
  return maxx == 1LL * p[id].first * (x - m) + p[id].second;
}
int binarysearch(int l, int r, int id) {
  if (l == r) return l;
  if (r - l == 1) {
    if (check(r, id))
      return r;
    else
      return l;
  }
  int mid = (l + r) / 2;
  if (check(mid, id))
    return binarysearch(mid, r, id);
  else
    return binarysearch(l, mid - 1, id);
}
int main() {
  scanf("%d%d%d", &n, &m, &qq);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &u, &v, &w);
    mp[u].push_back(make_pair(v, w));
    mp[v].push_back(make_pair(u, w));
    maxw[u] = max(maxw[u], w);
    maxw[v] = max(maxw[v], w);
  }
  q.push(make_pair(1, 0));
  while (!q.empty()) {
    now = q.front().first;
    step = q.front().second;
    q.pop();
    if (step == m) continue;
    for (int i = 0; i < mp[now].size(); i++) {
      if (!dis[mp[now][i].first][step + 1])
        q.push(make_pair(mp[now][i].first, step + 1));
      dis[mp[now][i].first][step + 1] = max(dis[mp[now][i].first][step + 1],
                                            dis[now][step] + mp[now][i].second);
      ans[step + 1] = max(ans[step + 1], dis[mp[now][i].first][step + 1]);
    }
  }
  for (int i = 1; i <= m; i++) ans[i] = (ans[i - 1] % mod + ans[i] % mod) % mod;
  for (int i = 1; i <= n; i++) p[i] = make_pair(maxw[i], dis[i][m]);
  sort(p + 1, p + n + 1);
  last = m + 1;
  anss = ans[m];
  for (int i = 1; i <= n; i++) {
    if (last > qq) break;
    t = binarysearch(last - 1, qq, i);
    if (t >= last) {
      aa = (1LL * p[i].first * (last - m) % mod + p[i].second % mod) % mod;
      an = (aa + 1LL * (t - last) * p[i].first % mod) % mod;
      anss = (anss + 1LL * (aa + an) * (t - last + 1) % mod * inv2 % mod) % mod;
    }
    last = t + 1;
  }
  printf("%d\n", anss);
  return 0;
}
