// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

struct UnionFind {
    V<ll> rank;
    V<ll> parent;

    UnionFind(ll N) : rank(N, 0), parent(N) {
        iota(parent.begin(), parent.end(), 0ll);
    }

    ll find(ll child) {
        return (child == parent[child] ? child : parent[child] = find(parent[child]));
    }

    void unit(ll x, ll y) {
        ll px = find(x);
        ll py = find(y);
        if(px == py) return;
        if(rank[px] < rank[py]) swap(px, py);
        parent[py] = px;
        rank[px] += (rank[px] == rank[py]);
    }

    bool same(ll x, ll y) {
        return (find(x) == find(y));
    }
};

const ll mod = 1e9 + 7;
V<TLL> edges;
ll cnt_crtcl;
ll cnt_over;
ll N, M, X;

void check(ll u, ll v, ll c) {
    UnionFind uf(N);
    ll cost = c;
    uf.unit(u, v);
    for(auto &&ele : edges) {
        ll f, t, c;
        tie(f, t, c) = ele;
        if(uf.same(f, t)) continue;
        uf.unit(f, t);
        cost += c;
    }

    DEBUG(make_tuple(u, v, cost));
    if(cost == X) cnt_crtcl++;
    if(X < cost) cnt_over++;
}

ll mod_pow(ll n, ll k) {
    ll ret = 1;
    ll cur = n;
    while(k) {
        if(k & 1) (ret *= cur) %= mod;
        k /= 2;
        cur = cur * cur % mod;
    }
    return ret;
}

int main() {
    cin >> N >> M >> X;
    for(ll i = 0; i < M; i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        edges.emplace_back(u - 1, v - 1, w);
    }

    sort(ALL(edges), [](TLL a, TLL b) { return get<2>(a) < get<2>(b); });
    for(auto &&ele : edges) {
        ll u, v, c;
        tie(u, v, c) = ele;
        check(u, v, c);
    }

    ll ans = 0;
    DEBUG(make_tuple(cnt_crtcl, cnt_over));
    if(cnt_crtcl && cnt_crtcl + cnt_over == M) {
        ll cnt_a = mod_pow(2, N - 1);
        cnt_a += mod - 2;
        cnt_a = cnt_a * mod_pow(2, M - (N - 1)) % mod;

        ll cnt_b = 0;
        if(N - 1 < cnt_crtcl) {
            cnt_b = mod_pow(2, cnt_crtcl - (N - 1));
            cnt_b += mod - 1;
            cnt_b = cnt_b * mod_pow(2, cnt_over) % mod;
            cnt_b = cnt_b * 2 % mod;
        }

        ans = (cnt_a + cnt_b) % mod;
    } else if(cnt_crtcl) {
        ans = mod_pow(2, cnt_crtcl);
        ans += mod - 1;
        ans = ans * mod_pow(2, cnt_over) % mod;
        ans = ans * 2 % mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 384