#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int mod=1e9+7;
int Pow(int x,int y) {
	int res=1;
	while(y) {
		if(y&1) res=res*(ll)x%mod;
		x=x*(ll)x%mod,y>>=1;
	}
	return res;
}
const int N=1010,M=2010;
int head[N],ecnt;
struct ed { int to,next,w; }e[N<<1];
void ad(int x,int y,int w) {
	e[++ecnt]=(ed){y,head[x],w}; head[x]=ecnt;
	e[++ecnt]=(ed){x,head[y],w}; head[y]=ecnt;
}
int gl,qmx;
void dfs(int u,int last,int mx) {
	if(u==gl) { qmx=mx; return; }
	for(int k=head[u];k;k=e[k].next) {
		int v=e[k].to; if(v==last) continue;
		dfs(v,u,max(mx,e[k].w));
	}
}
int Query(int x,int y) {
	gl=y;
	dfs(x,0,0);
	return qmx;
}
struct edge {
	int x,y,w;
	friend bool operator < (edge A,edge B) { return A.w<B.w; }
}E[M];
int used[M];
int fa[N];
int find(int x) { return fa[x]==x?x:fa[x]=find(fa[x]); }
bool un(int x,int y) {
	if(find(x)==find(y)) return 0;
	fa[find(x)]=find(y); return 1;
}
ll X;
int n,m;
int main() {
	rd(n),rd(m),rd(X);
	for(int i=1;i<=m;++i) rd(E[i].x),rd(E[i].y),rd(E[i].w);
	sort(E+1,E+m+1);
	for(int i=1;i<=n;++i) fa[i]=i;
	ll ans=0;
	for(int i=1;i<=m;++i)
		if(un(E[i].x,E[i].y)) ad(E[i].x,E[i].y,E[i].w),ans+=E[i].w,used[i]=1;
	int cnt0=0,cnt1=0,cnt2=0;
	ll del=X-ans;
	if(del<0) {
		printf("0"); return 0;
	}
	for(int i=1;i<=m;++i) if(!used[i]) {
		int t=E[i].w-Query(E[i].x,E[i].y);
		if(t>del) cnt2++;
		else if(t==del) cnt1++;
		else cnt0++;
	}
	if(del==0)
		printf("%d\n",((Pow(2,n-1)-2)*(ll)Pow(2,m-(n-1))%mod+2ll*(Pow(2,cnt1)-1)*Pow(2,cnt2)%mod+mod)%mod);
	else
		printf("%d\n",(2ll*Pow(2,cnt2)*(ll)(Pow(2,cnt1)-1)%mod+mod)%mod);
	return 0;
}