import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

import std.typecons;
alias Edge = Tuple!(int, "a", int, "b", int, "cost");

void main() {
    int n, m;
    scan(n, m);
    long x;
    scan(x);

    auto es = new Edge[](m);
    foreach (i ; 0 .. m) {
        int u, v, w;
        scan(u, v, w);
        u--, v--;
        es[i] = Edge(u, v, w);
    }

    es.sort!"a.cost < b.cost"();

    auto d = new long[](m);
    foreach (i ; 0 .. m) {
        auto uf = UnionFind(n);
        uf.unite(es[i].a, es[i].b);
        long wei = es[i].cost;

        foreach (j ; 0 .. m) {
            if (uf.same(es[j].a, es[j].b)) continue;
            uf.unite(es[j].a, es[j].b);
            wei += es[j].cost;
        }

        d[i] = wei;
    }

    auto ds = d.sort();

    debug {
        writeln("ds:", ds);
    }

    long f(long y) {
        return powmod(2, min(m, m - ds.lowerBound(y + 1).length.to!int + 1));
    }

    long ans = f(x - 1) - f(x);
    ans %= mod;
    if (ans < 0) ans += mod;

    writeln(ans);
}

immutable(long) mod = 10^^9 + 7;

long powmod(long x, long y) {
    return y > 0 ? powmod(x, y>>1)^^2 % mod * x^^(y&1) % mod : 1L;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

struct UnionFind {
    private {
        int _size;
        int[] _parent;
    }

    this(int N) 
    in {
        assert(N > 0);
    }
    body {
        _size = N;
        _parent = new int[](_size);
        foreach (i ; 0 .. _size) {
            _parent[i] = i;
        }
    }

    int findRoot(int x)
    in {
        assert(0 <= x && x < _size);
    }
    body {
        if (_parent[x] != x) {
            _parent[x] = findRoot(_parent[x]);
        }

        return _parent[x];
    }

    bool same(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        return findRoot(x) == findRoot(y);
    }

    void unite(int x, int y)
    in {
        assert(0 <= x && x < _size);
        assert(0 <= y && y < _size);
    }
    body {
        int u = findRoot(x);
        int v = findRoot(y);

        if (u == v) return;

        _parent[v] = u;
    }
}