#include<bits/stdc++.h>
using namespace std;
#define ll long long

const int mod=1e9+7;

ll K(ll x,ll y=mod-2){
    ll t=1;
    for (;y;y>>=1,x=x*x%mod)
        if (y&1) t=t*x%mod;
    return t;
}

int n, m, fa[1010]; ll aim, c0, c1, c2;
struct E{
    int u, v, w;
}e[2020];

int GF(int x){
    return x==fa[x]? x: fa[x]=GF(fa[x]);
}

ll calc(int id){
    ll res=e[id].w;
    for (int i=1;i<=n;++i) fa[i]=i;
    fa[GF(e[id].u)]=GF(e[id].v);
    for (int i=1;i<=m;++i){
        if (i==id) continue;
        int u=e[i].u, v=e[i].v;
        if (GF(u)!=GF(v)){
            fa[GF(u)]=GF(v);
            res+=e[i].w;
        }
    }
    return res;
}

int main(){
    cin>>n>>m>>aim;
    for (int i=1;i<=m;++i)
        cin>>e[i].u>>e[i].v>>e[i].w;
    sort(e+1,e+m+1,[](E a,E b){return a.w<b.w;});
    
    for (int i=1;i<=m;++i){
        ll t=calc(i);
        if (t==aim) ++c1;
        else if (t<aim) ++c0;
        else ++c2;
    }
    ll ans;
    if (!c1) return puts("0"), 0;
    if (c0){
        ans=2*(K(2,c1)-1)*K(2,c2)%mod;
    }else{
        ans=(K(2,c1)-2+mod)*K(2,c2)%mod;
    }
    cout<<ans<<endl;
}