// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;
#define int LL

const int inf = 1e9,maxn=2e5+5,mod=1e9+7;

int n,m,lim,fa[maxn];
struct ee{int x,y,z;}e[maxn];
int cmp(ee a,ee b){return a.z<b.z;}
int find(int x){return fa[x] == x?fa[x]:fa[x]=find(fa[x]);}
void un(int x,int y){int fx=find(x),fy=find(y);if(fx!=fy)fa[fy]=fx;} 
int pw(int x,int y){
	if(y==0)return 1;if(y==1)return x;int mid=pw(x,y>>1);
	if(y&1)return 1ll*mid*mid%mod*x%mod;return 1ll*mid*mid%mod;
}
int kruskal(){
	for(int i=1;i<=n;i++)fa[i]=i;
	int mst=0;
	for(int i=1;i<=m;i++){
		int x=e[i].x,y=e[i].y;
		int fx=find(x),fy=find(y);
		if(fx!=fy){
			mst+=e[i].z;
			fa[fy]=fx;
		}
	}
	return mst;
}

int kruskal(int fo){
	for(int i=1;i<=n;i++)fa[i]=i;
	int ffx=find(e[fo].x),ffy=find(e[fo].y);
	fa[ffy] = ffx;
	int mst=e[fo].z;
	for(int i=1;i<=m;i++){
		if(i==fo)continue;
		int x=e[i].x,y=e[i].y;
		int fx=find(x),fy=find(y);
		if(fx!=fy){
			mst+=e[i].z;
			fa[fy]=fx;
		}
	}
	return mst;
}

signed main(){
	scanf("%lld%lld%lld",&n,&m,&lim);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld%lld",&e[i].x,&e[i].y,&e[i].z);
	}
	sort(e+1,e+m+1,cmp);
	int orig = kruskal();
	if(lim<orig)return puts("0"), 0;
	if(lim==orig){
		int fce=0;
		for(int i=1;i<=m;i++){
			int nw = kruskal(i);
			if(nw == orig)++ fce;
		}
		printf("%lld\n",1ll*(pw(2,fce)-2+mod)%mod*pw(2,m-fce)%mod);
		return 0;
	}
	int fce=0,fcd=0;
	for(int i=1;i<=m;i++){
		int nw = kruskal(i);
		if(nw == lim)++ fce;
		else if(nw>lim) ++ fcd;
	}
	printf("%lld\n",2ll*((pw(2,fce)-1))%mod*pw(2,fcd)%mod);

	return 0;
}
