#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
typedef pair< int, Pi > Pii;
struct edge {
  int to, bit;
};
const static int INF = 1 << 30;

int main()
{
  int N, M, E, S, T, R;
  vector< edge > graph[100];
  int NextBit[100] = {};

  cin >> N >> M >> E >> S >> T >> R;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back((edge){b, -1});
    graph[b].push_back((edge){a, -1});
  }
  for(int i = 0; i < E; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    NextBit[c] |= 1 << i;
    graph[a].push_back((edge){b, i});
    graph[b].push_back((edge){a, i});
  }

  queue< Pii > Que;
  vector< vector< vector< int > > > v(N, vector< vector< int > >(R + 1, vector< int >(1 << E, INF)));
  Que.push(make_pair(0, make_pair(S, NextBit[S])));
  v[S][0][NextBit[S]] = 0;
  while(!Que.empty()) {
    Pii p = Que.front(); Que.pop();
    if(p.second.first == T) {
      cout << v[p.second.first][p.first][p.second.second] << endl;
      exit(0);
    }
    if(p.first < R) {
      for(int i = 0; i < graph[p.second.first].size(); i++) {
        const edge& e = graph[p.second.first][i];
        if(e.bit != -1 && !((p.second.second >> e.bit) & 1)) continue;
        if(v[e.to][p.first + 1][p.second.second|NextBit[e.to]] <= v[p.second.first][p.first][p.second.second] + 1) continue;
        v[e.to][p.first + 1][p.second.second|NextBit[e.to]] = v[p.second.first][p.first][p.second.second] + 1;
        Que.push(make_pair(p.first + 1, make_pair(e.to, p.second.second|NextBit[e.to])));
      }
    }
    if(v[S][0][p.second.second] <= v[p.second.first][p.first][p.second.second] + 1) continue;
    v[S][0][p.second.second] = v[p.second.first][p.first][p.second.second] + 1;
    Que.push(make_pair(0, make_pair(S, p.second.second)));
  }
  cout << -1 << endl;
}