#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define mod 1000000007
#define MM 2005
#define MN 1005
using namespace std;
inline ll in(){
    ll x=0ll;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct edge{
	int fr,to;
	ll val;
}e[MM];
int fa[MN],n,m,sum1,sum2;
ll sum,x;
inline bool cmp(edge x,edge y){
	return (x.val==y.val)?x.fr<y.fr:x.val<y.val;
}
inline int gf(int x){
	return fa[x]?fa[x]=gf(fa[x]):x;
}
inline int qpow(int x,int k){
	int res=1;
	while (k){
		if (k&1) res=(1ll*res*x)%mod;
		x=(1ll*x*x)%mod;k>>=1;
	}return res;
}
int main()
{
	n=in();m=in();x=in();sum2=1;
	for (int i=1;i<=m;++i){
		e[i].fr=in();e[i].to=in();e[i].val=in(); 
	}sort(e+1,e+m+1,cmp);
	for (int i=2;i<=m;++i){
		memset(fa,0,sizeof(fa));sum=0;
		int fx=gf(e[i].fr),fy=gf(e[i].to);
		if (fx!=fy) fa[fx]=fy,sum+=e[i].val;
		for (int j=1;j<=m;++j){
			fx=gf(e[j].fr),fy=gf(e[j].to);
			if (fx!=fy) fa[fx]=fy,sum+=e[j].val;
		}if (sum==x) ++sum1;if (sum>x) ++sum2;
	}
	printf("%d",(1ll*(qpow(2,sum1)+mod-1)%mod*qpow(2,sum2)%mod)%mod);
	return 0;
}