#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

const ll mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

class UnionFind{
private:
    vector<int> p,s;
	int cnt;
public:
	UnionFind(){}
	UnionFind(int N){
        p = s = vector<int>(N+1,0);
        init(N);
    }
	void init(int N){
    	cnt = N;
		for(int i=1;i<=N;i++){
			p[i] = i; s[i] = 1;
		}
	}
	int find(int x){
		if(p[x]==x) return x;
		else return p[x] = find(p[x]);
	}
	void unite(int x,int y){
		x = find(x); y = find(y);
		if(x==y) return;
		if(s[x]>s[y]){
			p[y] = x;
			s[x] += s[y];
		}else{
			p[x] = y;
			s[y] += s[x];
		}
		cnt--;
	}
	bool is_same_set(int x,int y) {return find(x)==find(y);}
	int size(int x) {return s[find(x)];}
	int compnents_number(){return cnt;}
};

struct edge{
    int id;
    int s,t;
    ll c;
    bool operator<(const edge& r)const{
        return c<r.c;
    }
};

int main(){
    int N,M;
    ll X;
    cin >> N >> M >> X;
    vector<edge> E(M);
    for(int i=0;i<M;i++){
        int s,t; ll c;
        cin >> s >> t >> c;
        E[i] = {i,s,t,c};
    }
    sort(E.begin(),E.end());
    vector<mint> fact(M+1,1);
    for(ll i=1;i<=M;i++) fact[i] = fact[i-1]*2;
    set<int> sx,use;
    set<int> ok;
    UnionFind uf(N);
    for(auto x:E){
        uf.init(N);
        use.clear();
        ll cost = 0;
        uf.unite(x.s,x.t);
        cost += x.c;
        for(auto y:E){
            if(x.id==y.id) continue;
            if(!uf.is_same_set(y.s,y.t)){
                cost += y.c;
                uf.unite(y.s,y.t);
                use.insert(y.id);
            }
        }
        if(uf.size(1)!=N) continue;
        if(cost<X){
            sx.insert(x.id);
            for(auto u:use){
                sx.insert(u);
            }
        }
    }
    for(auto x:E){
        if(sx.count(x.id)==1) continue;
        uf.init(N);
        ll cost = 0;
        uf.unite(x.s,x.t);
        cost += x.c;
        for(auto y:E){
            if(x.id==y.id) continue;
            if(!uf.is_same_set(y.s,y.t)){
                cost += y.c;
                uf.unite(y.s,y.t);
            }
        }
        if(uf.size(1)!=N) continue;
        if(cost==X) ok.insert(x.id);
    }
    if(ok.size()==0){
        cout << 0 << endl;
        return 0;
    }
//    cerr << sx.size() << " " << ok.size() << endl;
    int res = M-(int)(sx.size()+ok.size());
    mint ans = 0;
    if(sx.size()==0) ans = fact[ok.size()]-2;
    else ans = (fact[ok.size()]-1)*2;
    ans *= fact[res];
    cout << ans.x << endl;
}

Measured memory_bytes: 512