#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N,M,E,S,T,R,a[8],b[8],c[8],inf=1e9;
vector<int> G[100];
int d[100][101][1<<8];
int main(){
	cin>>N>>M>>E>>S>>T>>R;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		G[a].pb(b),G[b].pb(a);
	}
	rep(i,E) cin>>a[i]>>b[i]>>c[i];
	rep(i,N) rep(j,R+1) rep(k,1<<E) d[i][j][k]=inf;
	deque<int> ps,rs,bs;
	ps.pb(S),rs.pb(0),bs.pb(0);
	d[S][0][0]=0;
	while(!ps.empty()){
		hoge:
		int v=ps.front(),r=rs.front(),bt=bs.front();
		ps.pop_front();rs.pop_front();bs.pop_front();
//		cout<<v<<" "<<r<<" "<<bt<<"  d="<<d[v][r][bt]<<endl;
		if(v==T){
			cout<<d[v][r][bt]<<endl;
			return 0;
		}
		rep(i,E){
			if(c[i]==v&& ((bt>>i)&1)==0 ){
				int nbt=bt+(1<<i);
				if(d[v][r][nbt]==inf){
					ps.push_front(v);
					rs.push_front(r);
					bs.push_front(nbt);
					d[v][r][nbt]=d[v][r][bt];
					goto hoge;
				}
			}
		}
		if(r<R){
			for(int u:G[v]){
				if(d[u][r+1][bt]==inf){
					ps.pb(u);
					rs.pb(r+1);
					bs.pb(bt);
					d[u][r+1][bt]=d[v][r][bt]+1;
				}
			}
			rep(i,E){
				if((bt>>i)&1){
					if(a[i]==v) swap(b[i],a[i]);
					if(b[i]==v){
						int u=a[i];
						if(d[u][r+1][bt]==inf){
							ps.pb(u);
							rs.pb(r+1);
							bs.pb(bt);
//							if(u==5){
//								cout<<"   "<<v<<" "<<r<<" "<<bt<<endl;
//							}
							d[u][r+1][bt]=d[v][r][bt]+1;
						}
					}
				}
			}
		}
		if(d[S][0][bt]==inf){
			ps.pb(S);
			rs.pb(0);
			bs.pb(bt);
			d[S][0][bt]=d[v][r][bt]+1;
		}
	}
	puts("-1");
}