//---includes---//
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
//---defines---//
#define MAX_N 200
#define MAX_M 10000
#define INF 1 << 30
#define MAX_E 5
//---ints---//
int N, M, E, S, T, R;
int A[MAX_M], B[MAX_M];
vector<int> X[1 << MAX_E][MAX_N];
int E1[MAX_E][2], F[MAX_E], power[MAX_E];
int DP[1 << MAX_E][MAX_N], DP2[1 << MAX_E], maxn[MAX_N];
queue<pair<int, int>>Q;
//---bfs---//
int bfs() {
	DP[0][S] = 0;
	Q.push(make_pair(0, S));
	for (int i = 0; i < MAX_E; i++)
	{
		int AA = 0;
		if (i >= 1) {
			AA = 1;
		}
		for (int j = 0; j < (1 << MAX_E); j++) {
			DP2[j] = INF;
			for (int k = 0; k < N; k++) {
				DP2[j] = min(DP2[j], DP[j][k] + AA);
			}
		}
		for (int j = 0; j < (1 << MAX_E); j++) {
			for (int k = 0; k < MAX_N; k++) {
				DP[j][k] = INF;
			}
		}
		for (int j = 0; j < (1 << MAX_E); j++) {
			DP[j][S] = DP2[j];
			if (DP[j][S] < INF) {
				Q.push(make_pair(j, S));
			}
		}
		while (!Q.empty()) {
			pair<int, int>pa = Q.front();
			Q.pop();
			int a1 = pa.first;
			int a2 = pa.second;
			for (int j = 0; j < X[a1][a2].size(); j++) {
				int a3 = X[a1][a2][j];
				int a4 = 0;
				for (int j = 0; j < E; j++) {
					if ((a1 / power[j]) % 2 == 0) {
						if (F[j] == a3) {
							a4 += power[j];
						}
					}
				}
				a4 += a1;
				if (DP[a4][a3] > DP[a1][a2] + 1) {
					DP[a4][a3] = DP[a1][a2] + 1;
					Q.push(make_pair(a4, a3));
				}
			}
		}
		for (int j = 0; j < (1 << MAX_E); j++) {
			for (int k = 0; k < MAX_N; k++) {
				maxn[k] = min(maxn[k], DP[j][k]);
			}
		}
	}
	return maxn[T];
}
//---memset---//
void _memset() {
	N = 0; M = 0; E = 0; S = 0; T = 0; R = 0;
	for (int i = 0; i < MAX_M; i++) {
		A[i] = 0;
		B[i] = 0;
	}
	for (int i = 0; i < MAX_E; i++) {
		power[i] = 0;
		E1[i][0] = 0;
		E1[i][1] = 0;
		F[i] = 0;
	}
	for (int i = 0; i < (1 << MAX_E); i++) {
		while (!Q.empty()) {
			Q.pop();
		}
		for (int j = 0; j < MAX_N; j++) {
			DP[i][j] = INF;
			maxn[j] = INF;
		}
	}
}
//---main---//
int main() {
	_memset();
	power[0] = 1;
	for (int i = 1; i < MAX_E; i++) {
		power[i] = power[i - 1] * 2;
	}
	cin >> N >> M >> E >> S >> T >> R;
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}
	for (int i = 0; i < E; i++) {
		cin >> E1[i][0] >> E1[i][1] >> F[i];
	}
	for (int i = 0; i < (1 << E); i++) {
		for (int j = 0; j < M; j++) {
			X[i][A[j]].push_back(B[j]);
			X[i][B[j]].push_back(A[j]);
		}
		for (int j = 0; j < E; j++) {
			if ((i / power[j]) % 2 == 1) {
				X[i][E1[j][0]].push_back(E1[j][1]);
				X[i][E1[j][1]].push_back(E1[j][0]);
			}
		}
	}
	int RES = bfs();
	if (RES >= INF) {
		RES = -1;
	}
	cout << RES << endl;
	return 0;
}