#include<cstdio>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define MAXN 1000
#define MAXM 2000
#define MO 1000000007
#define LL long long
int n,m;
LL x,sum,ans;
struct node
{
	int u,v,len;
}line[MAXM+5];
bool cmp(node a,node b)
{
	return a.len<b.len;
}
int bits[MAXM+5],dif[MAXM+5];
void Pre()
{
	bits[0]=1;
	for(int i=1;i<=m;i++)
		bits[i]=2LL*bits[i-1]%MO;
}
int fa[MAXN+5],deep[MAXN+5],val[MAXN+5];
int FindSet(int x)
{
	if(fa[x]==0) return x;
	return fa[x]=FindSet(fa[x]);
}
bool used[MAXM+5];
vector<int>G[MAXN+5],W[MAXN+5];
void Build(int u,int pa)
{
	deep[u]=deep[pa]+1;
	fa[u]=pa;
	for(int i=0;i<G[u].size();i++)
		if(G[u][i]==pa)
			val[u]=W[u][i];
		else Build(G[u][i],u);
}
int Find_max(int u,int v)
{
	if(deep[u]<deep[v])
		swap(u,v);
	int ret=0;
	while(deep[u]>deep[v])
	{
		ret=max(ret,val[u]);
		u=fa[u];
	}
	while(u!=v)
	{
		ret=max(ret,max(val[u],val[v]));
		u=fa[u],v=fa[v];
	}
	return ret;
}
int main()
{
	scanf("%d%d%lld",&n,&m,&x);
	Pre();
	for(int i=0;i<m;i++)
		scanf("%d%d%d",&line[i].u,&line[i].v,&line[i].len);
	sort(line,line+m,cmp);
	for(int i=0;i<m;i++)
	{
		int u=FindSet(line[i].u);
		int v=FindSet(line[i].v);
		if(u!=v)
		{
			sum+=line[i].len;
			used[i]=1;
			fa[u]=v;
			G[line[i].u].push_back(line[i].v);
			G[line[i].v].push_back(line[i].u);
			W[line[i].u].push_back(line[i].len);
			W[line[i].v].push_back(line[i].len);
		}
	}
	x-=sum;
	if(x<0)
	{
		printf("0\n");
		return 0;
	}
	Build(1,0);
	int cnt=0;
	for(int i=0;i<m;i++)
		if(!used[i])
		{
			int x=Find_max(line[i].u,line[i].v);
			dif[++cnt]=line[i].len-x;
		}
	sort(dif+1,dif+1+cnt);
	if(x==0)
		ans=(bits[m]-2LL*bits[m-n+1]+2LL*MO)%MO;
	for(int i=1;i<=cnt;i++)
		if(dif[i]==x)
		{
			ans+=2LL*bits[cnt-i];
			ans%=MO;
		}
	printf("%lld\n",ans);
}