#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;//vertex, event, day
struct edge{
  int to;
  bool okarina;
};
int main(int argc, char *argv[]){
  int n, m, E, s, t, r;
  cin >> n >> m >> E >> s >> t >> r;
  vector<vector<vector<edge> > >g((1<<E),vector<vector<edge> >(n, vector<edge>()));
  for (int i = 0; i < m; i++) {
    int to, from;
    cin >> to >> from;
    for (int j = 0; j < (1<<E); j++) {
      g[j][to].push_back(edge{from, 0});
      g[j][from].push_back(edge{to, 0});
    }
  }
  int a, b, c;
  map<int, int> add_edge;
  for (int i = 0; i < E; i++) {
    cin >> a >> b >> c;
    for (int j = 0; j < (1<<E); j++) {
      if(j & (1 << i)){
        g[j][a].push_back(edge{b, 0});
        g[j][b].push_back(edge{a, 0});
      }
    }
    add_edge[c] = i;
  }
  for (int i = 0; i < (1<<E); i++) {
    for (int j = 0; j < n; j++) {
      g[i][j].push_back(edge{s, 1});
    }
  }

  // for (int i = 0; i < (1<<E); i++) { 
  //   std::cout << "event:" << i << std::endl;
  //   for (int j = 0; j < n; j++) {
  //     std::cout << "v:" << j << std::endl;
  //     for (int k = 0; k < g[i][j].size(); k++) {
  //       std::cout << g[i][j][k].to << " ";
  //     }
  //     std::cout <<  std::endl;
  //   }
  //     std::cout <<  std::endl;
  // }
  queue<piii> que;
  int dp[(1<<E)][r + 1][n];
  for (int i = 0; i < (1<<E); i++) {
    for (int j = 0; j <= r; j++) {
      for (int k = 0; k < n; k++) {
        dp[i][j][k] = 1e9;
      }
    }
  }
  if(add_edge.count(s)){
    dp[(1<<add_edge[s])][0][s] = 0;
    que.push(piii(s, pii((1<<add_edge[s]), 0)));
  }else{
    dp[0][0][s] = 0;
    que.push(piii(s, pii(0, 0)));
  }
  while(!que.empty()){
    int v = que.front().first;
    int event = que.front().second.first;
    int day = que.front().second.second;
    que.pop();
    if(day == r){
      if(dp[event][0][s] > dp[event][r][v] + 1){
        dp[event][0][s] = dp[event][r][v] + 1;
        que.push(piii(s, pii(event, 0)));
      }
      continue;
    }
    int new_event = event;
    if(add_edge.count(v)){
      //std::cout << "get event:" << v << std::endl;
      new_event |= (1<<add_edge[v]);
    }
    // std::cout << "new_event:" << new_event << std::endl;
    // std::cout << "        v:" << v << std::endl;

    for (int i = 0; i < g[new_event][v].size(); i++) {
      edge e = g[new_event][v][i];
      if(!e.okarina){
        if(dp[new_event][day + 1][e.to] >
           dp[event][day][v] + 1){
          dp[new_event][day + 1][e.to] = dp[event][day][v] + 1;
          que.push(piii(e.to, pii(new_event, day + 1)));
        }
      }else{
        if(dp[new_event][0][e.to] > dp[event][day][v] + 1){
          dp[new_event][0][e.to] = dp[event][day][v] + 1;
          que.push(piii(e.to, pii(new_event, 0)));
        }
      }
    }
  }
  int ans = 1e9;
  for (int i = 0; i < (1<<E); i++) {
    for (int j = 0; j <= r; j++) {
      ans = min(ans, dp[i][j][t]);
    }
  }
  if(ans == 1e9)std::cout << -1 << std::endl;
  else std::cout << ans << std::endl;

  return 0;
}