// Slower C++ solution:
#include <bits/stdc++.h>



using namespace std;



const int max_n = 2022, mod = 1000000007;



struct edge {

    int u, v, d;



    bool operator < (const edge &e) const {

        return d < e.d;

    }

};



int mul(int x, int y) {

    return 1LL * x * y % mod;

}



int n, m, p[max_n], pw[max_n];

edge e[max_n];

bool take[max_n];

vector<int> g[max_n], d[max_n];

long long x;



int find_set(int v) {

    if (v == p[v]) {

        return v;

    }

    return p[v] = find_set(p[v]);

}



bool union_set(int v1, int v2) {

    v1 = find_set(v1);

    v2 = find_set(v2);

    if (v1 == v2) {

        return false;

    }

    p[v1] = v2;

    return true;

}



int get_max(int v, int fin, int mx, int p) {

    if (v == fin) {

        return mx;

    }

    int res = -1;

    for (int i = 0; i < g[v].size(); ++i) {

        const int to = g[v][i], c = d[v][i];

        if (to == p) {

            continue;

        }

        res = max(res, get_max(to, fin, max(mx, c), v));

    }

    return res;

}



int main() {

    //freopen("input.txt", "r", stdin);

    //freopen("output.txt", "w", stdout);

    pw[0] = 1;

    for (int i = 1; i < max_n; ++i) {

        pw[i] = mul(pw[i - 1], 2);

    }

    cin >> n >> m >> x;

    if (n <= 2) {

        cout << 0 << endl;

        return 0;

    }

    for (int i = 0; i < m; ++i) {

        cin >> e[i].u >> e[i].v >> e[i].d;

        --e[i].u;

        --e[i].v;

    }

    sort(e, e + m);

    for (int i = 0; i < n; ++i) {

        p[i] = i;

    }

    long long tot = 0;

    for (int i = 0; i < m; ++i) {

        take[i] = false;

        if (union_set(e[i].u, e[i].v)) {

            take[i] = true;

            tot += e[i].d;

            g[e[i].u].push_back(e[i].v);

            d[e[i].u].push_back(e[i].d);

            g[e[i].v].push_back(e[i].u);

            d[e[i].v].push_back(e[i].d);

        }

    }

    int ans = 0;

    if (tot == x) {

        ans += mul(pw[n - 1] + mod - 2, pw[m - n + 1]);

    }

    vector<int> all;

    for (int i = 0; i < m; ++i) {

        if (!take[i]) {

            int mx = get_max(e[i].u, e[i].v, -1, -1);

            all.push_back(e[i].d - mx);

        }

    }

    sort(all.begin(), all.end());

    for (int i = 0; i < all.size(); ++i) {

        if (tot + all[i] == x) {

            ans += pw[all.size() - i];

            ans %= mod;

        }

    }

    cout << ans << endl;

    return 0;

}


// Faster C++ solution for the same problem (measured speedup: 1.1303518686557887x):
#include <cstdio>

#include <cstring>

#include <iostream>

#include <algorithm>

using namespace std;

#define M 2005

#define N 1005

#define ll long long

#define mod 1000000007

int A[M], B[M], C[M], idx[M];

int fir[N], nex[M << 1], tar[M << 1], len[M << 1], cnt;

int dep[N], bel[N], vis[M];

int m, n, f[15][N], g[15][N];

ll s;

bool E[M];

bool cmp(int u, int v){return C[u] < C[v];}

int Getbel(int x){return bel[x] ? bel[x] = Getbel(bel[x]) : x;}

void Add(int a, int b, int c)

{

	++cnt;

	tar[cnt] = b;

	nex[cnt] = fir[a];

	len[cnt] = c;

	fir[a] = cnt;

}

void Dfs(int r)

{

	for (int i = fir[r]; i; i = nex[i])

	{

		int v = tar[i];

		if (v != f[0][r])

		{

			dep[v] = dep[r] + 1;

			f[0][v] = r;

			g[0][v] = len[i];

			Dfs(v);

		}

	}

}

int main()

{

	scanf("%d%d%lld", &n, &m, &s);

	for (int i = 1; i <= m; i++)

	{

		scanf("%d%d%d", &A[i], &B[i], &C[i]);

		idx[i] = i;

	}

	sort(idx + 1, idx + m + 1, cmp);

	for (int i = 1; i <= m; i++)

	{

		int x = Getbel(A[idx[i]]), y = Getbel(B[idx[i]]);

		if (x != y)

		{

			vis[idx[i]] = 1;

			s -= C[idx[i]];

			bel[x] = y;

			Add(A[idx[i]], B[idx[i]], C[idx[i]]);

			Add(B[idx[i]], A[idx[i]], C[idx[i]]);

		}

	}

	Dfs(1);

	for (int i = 1; i <= 12; i++)

	{

		for (int j = 1; j <= n; j++)

		{

			f[i][j] = f[i - 1][f[i - 1][j]];

			g[i][j] = max(g[i - 1][j], g[i - 1][f[i - 1][j]]);

		}

	}

	int x = s ? 0: n - 2, y = 1;

	for (int i = 1; i <= m; i++)

		if (!vis[i])

		{

			int u = A[i], v = B[i], mx = 0;

			if (dep[u] < dep[v])

				swap(u, v);

			for (int j = 0; j <= 12; j++)

				if ((dep[u] - dep[v]) & (1 << j))

					mx = max(mx, g[j][u]), u = f[j][u];

			if (u == v)

			{

				if (s == C[i] - mx)x++;

				if (s < C[i] - mx)y++;

				continue;

			}

			for (int j = 12; j >= 0; j--)

				if (f[j][u] != f[j][v])

				{

					mx = max(mx, max(g[j][u], g[j][v]));

					u = f[j][u], v = f[j][v];

				}

			mx = max(mx, max(g[0][u], g[0][v]));

			if (s == C[i] - mx)x++;

			if (s < C[i] - mx)y++;

		}

	int ans = 0;

	for (int i = 0; i < x; i++)

		ans = (ans * 2ll + 1) % mod;

	for (int i = 0; i < y; i++)

		ans = (ans * 2ll) % mod;

	printf("%d\n", ans);

}