#include<bits/stdc++.h>
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m,e,s,t,r;
  cin>>n>>m>>e>>s>>t>>r;
  vector<vector<int>> g(n);
  lp(i,m){
    int a,b;
    cin>>a>>b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<vector<int>> ch(e);
  int ex[10];
  lp(i,e){
    int a,b,c;
    cin>>b>>a>>c;
    ex[i]=c;
    ch[i]={a,b};
  }
  int dp[110][100][110];
  dp[0][0][0]=0;
  lp(i,110){
    lp(j,100){
      lp(k,110){
	dp[i][j][k]=INF;
      }
    }
  }
  queue<vector<int>> q;
  q.push({s,0,0,0});
  int ans=INF;
  while(!q.empty()){
    int now=q.front()[0];
    int cnt=q.front()[1];
    int bit=q.front()[2];
    int tr=q.front()[3];
    q.pop();
    if(tr>r) continue;
    if(dp[now][bit][tr]<cnt) continue;
    if(cnt>ans) continue;
    if(now==t){
      ans=min(cnt,ans);
      continue;
    }
    int trs=0;
    lp(i,e){
      if(now==ex[i]&&!(bit&(1<<i))){
	bit|=(1<<i);
	trs=1;
      }
    }
    //cout<<now<<" "<<bit<<endl;
    lp(i,g[now].size()){
      int next=g[now][i];
      if(dp[next][bit][tr]>cnt+1){
	dp[next][bit][tr]=cnt+1;
	q.push({next,cnt+1,bit,tr+1});
      }
    }
    lp(i,e){
      if(bit&(1<<i)){
	if(ch[i][0]==now){
	  int next=ch[i][1];
	  if(dp[next][bit][tr]>cnt+1){
	    dp[next][bit][tr]=cnt+1;
	    q.push({next,cnt+1,bit,tr+1});
	  }
	}
	if(ch[i][1]==now){
	  int next=ch[i][0];
	  if(dp[next][bit][tr]>cnt+1){
	    dp[next][bit][tr]=cnt+1;
	    q.push({next,cnt+1,bit,tr+1});
	  }
	}
      }
      if(trs==1){
	int next=s;
	if(dp[next][bit][tr]>cnt+1){
	  dp[next][bit][tr]=cnt+1;
	  q.push({next,cnt+1,bit,0});
	}
      }
    }
    
  }
  if(ans==INF) cout<<-1<<endl;
  else cout<<ans<<endl;
  
  return 0;
}

