#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
const int N=1005;
const int M=2005;
#define mod 1000000007
using namespace std;
int diff[M];
struct node{
    int u,v,len;
    node(){}
    node(int u1,int v1,int len1):u(u1),v(v1),len(len1){}
    bool operator<(const node &x)const{return len<x.len;}
}line[M];
bool used[M];
long long x,sum;
int fa[N],fal[N],deep[N];
vector<int>a[N],w[N];
inline void swap(int &a,int &b){a^=b;b^=a;a^=b;}
inline int find(int x){return fa[x]?fa[x]=find(fa[x]):x;}
void build(int x,int fa1){
    fa[x]=fa1;
    deep[x]=deep[fa1]+1;
    for(int i=0;i<a[x].size();i++)
        if(a[x][i]==fa1)fal[x]=w[x][i];
        else build(a[x][i],x);
}
int findmax(int u,int v){
    int res=0;
    if(deep[u]<deep[v])swap(u,v);
    while(deep[u]>deep[v])res=max(res,fal[u]),u=fa[u];
    while(u!=v)res=max(res,max(fal[u],fal[v])),u=fa[u],v=fa[v];
    return res;
}
int n,m,u,v,val;
long long bits[M];
int main(){
    scanf("%d%d%lld",&n,&m,&x);bits[0]=1;
    for(int i=1;i<=m;i++)bits[i]=(bits[i-1]*2ll)%mod;
    for(int i=0;i<m;i++)scanf("%d%d%d",&u,&v,&val),line[i]=node(u,v,val);
    sort(line,line+m);
    for(int i=0;i<m;i++){
        int u=find(line[i].u),v=find(line[i].v);
        if(u!=v){
            fa[u]=v;
            sum+=line[i].len;
            a[line[i].u].push_back(line[i].v);
            a[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);
            used[i]=1;
        }
    }
    x-=sum;
    if(x<0)return 0*puts("0");
    memset(fa,0,sizeof fa);
    build(1,0);int cnt=0;
    for(int i=0;i<m;i++)
        if(used[i]==0){
            int maxd=findmax(line[i].u,line[i].v);
            diff[++cnt]=line[i].len-maxd;
        }
    sort(diff+1,diff+1+cnt);
    long long ans=0;
    if(x==0)ans=(bits[m]-2ll*bits[m-n+1]+2ll*mod)%mod;
    for(int i=1;i<=cnt;i++)if(x==diff[i])ans=(ans+2ll*bits[cnt-i])%mod;
    printf("%lld\n",ans);
    return 0;
}