#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int N=1005;
const int MOD=1000000007;
const int inf=1000000000;

int n,m,cnt,last[N],fa[N],dep[N],val[N],f[N];
struct edge{int to,next,w;}e[N*2];
struct data{int x,y,w,tag;}a[N*2];
LL X;

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int find(int x)
{
	if (f[x]==x) return x;
	else return f[x]=find(f[x]);
}

bool cmp(data a,data b)
{
	return a.w<b.w;
}

int ksm(int x,int y)
{
	int ans=1;
	while (y)
	{
		if (y&1) ans=(LL)ans*x%MOD;
		x=(LL)x*x%MOD;y>>=1;
	}
	return ans;
}

void addedge(int u,int v,int w)
{
	e[++cnt].to=v;e[cnt].w=w;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].w=w;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x)
{
	dep[x]=dep[fa[x]]+1;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa[x]) continue;
		val[e[i].to]=e[i].w;
		fa[e[i].to]=x;
		dfs(e[i].to);
	}
}

int get_mx(int x,int y)
{
	int mx=0;
	if (dep[x]<dep[y]) swap(x,y);
	while (dep[x]>dep[y]) mx=max(mx,val[x]),x=fa[x];
	while (x!=y) mx=max(mx,max(val[x],val[y])),x=fa[x],y=fa[y];
	return mx;
}

int main()
{
	n=read();m=read();scanf("%lld",&X);
	for (int i=1;i<=m;i++) a[i].x=read(),a[i].y=read(),a[i].w=read();
	for (int i=1;i<=n;i++) f[i]=i;
	sort(a+1,a+m+1,cmp);
	LL tot=0;
	for (int i=1;i<=m;i++)
	{
		int x=find(a[i].x),y=find(a[i].y);
		if (x!=y) f[x]=y,addedge(a[i].x,a[i].y,a[i].w),tot+=a[i].w;
	}
	dfs(1);
	int s1=0,s2=1;
	for (int i=2;i<=m;i++)
	{
		int mx=get_mx(a[i].x,a[i].y);
		if (tot-mx+a[i].w==X) s1++;
		else if (tot-mx+a[i].w>X) s2++;
	}
	printf("%d",(LL)(ksm(2,s1)-1)*ksm(2,s2)%MOD);
	return 0;
}