#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N, M, E, S, T, R;
    vector< vector<int> > G;
    vector<int> events;
    void input() {
        cin >> N >> M >> E >> S >> T >> R;
        G.clear(); G.resize(N, vector<int>(N, -1));
        for (int i = 0; i < M; i++) {
            int a, b; cin >> a >> b;
            G[a][b] = G[b][a] = 0;
        }
        events.clear(); events.resize(N, 0);
        for (int i = 0; i < E; i++) {
            int a, b, c; cin >> a >> b >> c;
            events[c] = (1 << i);
            G[a][b] = G[b][a] = (1 << i);
        }
    }

    const int MAX_E = 4;
    const int MAX_R = 100;
    const int MAX_N = 100;
    const int INF = 1<<28;

    struct State {
        int e, r, v, t;
        State(int e, int r, int v, int t) :
            e(e), r(r), v(v), t(t) {}
    };

    void solve() {
        static int D[1 << MAX_E][MAX_R + 1][MAX_N];
        for (int i = 0; i < (1 << MAX_E); i++) for (int j = 0; j <= MAX_R; j++) for (int k = 0; k < MAX_N; k++) {
            D[i][j][k] = INF;
        }
        D[0][0][S] = 0;
        queue<State> Q;
        Q.push(State(events[S], 0, S, 0));
        while (not Q.empty()) {
            State s = Q.front(); Q.pop();
            if (s.r < R) {
                for (int i = 0; i < N; i++) {
                    int x = G[s.v][i];
                    if (x < 0) continue;
                    if (x == 0 || (x & s.e)) {
                        int ne = s.e;
                        int nr = s.r + 1;
                        int nv = i;
                        int nt = s.t + 1;
                        if (events[i] > 0) ne |= events[i];
                        if (D[ne][nr][nv] > nt) {
                            D[ne][nr][nv] = nt;
                            Q.push(State(ne, nr, nv, nt));
                        }
                    }
                }
            }
            if (D[s.e][0][S] > s.t + 1) {
                D[s.e][0][S] = s.t + 1;
                Q.push(State(s.e, 0, S, s.t + 1));
            }
        }
        int ans = INF;
        for (int i = 0; i < (1 << MAX_E); i++) {
            for (int j = 0; j <= R; j++) {
                ans = min(ans, D[i][j][T]);
            }
        }
        cout << (ans == INF ? -1 : ans) << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}