#include<cstdio>
#include<algorithm>
#include<vector>
//分类讨论, 具体分析
//maximum update edge count = 1
struct Edge{
    int u,v;
    long long c;
    int id;
    Edge(int u=0,int v=0,long long c=0):u(u),v(v),c(c){}
    bool operator < (const Edge& other)const{
        return c<other.c;
    }
};
Edge e[2005];
int p[1005];
int vis[2005];
std::vector<Edge>g[1005]; 
int parent[1005]; long long dis[1005];
int reach[1005]; long long parentEdge[1005];

int find(int u){
    if(p[u]==u) return u;
    else return p[u] = find(p[u]);
}

void dfs(int u){
    for(Edge& edge: g[u]){
        int v = edge.v; long long c = edge.c;
        if(parent[v]==0){
            parentEdge[v] = c;
            parent[v] = u;
            dis[v] = dis[u]+c;
            dfs(v);
        }
    }
}

long long getMst(int n,int m){
    std::sort(e+1,e+1+m);
    long long ans = 0;
    for(int i = 1; i <= n; i++) p[i] = i;
    for(int i = 1; i <= m; i++){
        int x = e[i].u, y = e[i].v;
        long long c = e[i].c;
        int u = find(x), v = find(y);
        if(u!=v){
            vis[e[i].id] = 1;
            g[x].push_back(Edge(x,y,c));
            g[y].push_back(Edge(y,x,c));
            ans += e[i].c;
            p[u] = v;
        }
    }
    parent[1] = -1, dis[1] = 0;
    dfs(1);
    return ans;
}

int lca(int u,int v,int n){
    for(int i = 1; i <= n; i++) reach[i] = 0;
    while(u!=-1){
        reach[u] = 1;
        u = parent[u];
    } 
    while(!reach[v]) v = parent[v];
    return v;
}

long long max(long long a,long long b){ return a>b?a:b; }

long long getMaxEdge(int u,int v,int n){
    int p = lca(u,v,n);
    long long res = 0;
    while(u!=p){
        res = max(res,parentEdge[u]);
        u = parent[u];
    }
    while(v!=p){
        res = max(res,parentEdge[v]);
        v = parent[v];
    }
    return res;
}

const long long mod = 1e9+7;

long long power(long long a,long long b){
    long long res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b /= 2;
    }
    return res;
}

int main(){ 
    int n,m; long long x;
    scanf("%d%d%lld",&n,&m,&x);
    for(int i = 1; i <= m; i++){
        scanf("%d%d%lld",&e[i].u,&e[i].v,&e[i].c);
        e[i].id = i;
    }
    long long mst = getMst(n,m);
    long long diff = x-mst;
    if(diff<0){ printf("0\n"); return 0; }
    long long same = 0, lower = 0, mid = 0, upper = 0;
    for(int i = 1; i <= m; i++){
        if(vis[e[i].id]) continue;
        long long maxE = getMaxEdge(e[i].u,e[i].v,n);
        long long change = e[i].c-maxE;
        if(change==0) same++;
        else if(change<diff) lower++;
        else if(change==diff) mid++;
        else upper++;
    }
    //printf("diff = %lld, same = %lld, lower = %lld, mid = %lld, upper = %lld\n",diff,same,lower,mid,upper);    
    if(diff==0){
        long long all = power(2,m);
        long long minus = 2*power(2,lower+mid+upper)%mod;
        all -= minus;
        if(all<0) all += mod;
        printf("%lld\n",all);
    }
    else{
        //printf("?\n");
        long long all = power(2,mid);
        all--;
        if(all<0) all += mod;
        all = all*power(2,upper)%mod;
        all = all*2%mod;
        printf("%lld\n",all);
    }
    return 0;
}


Measured memory_bytes: 3436