#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef queue<ll> ql;
typedef set<ll> sl;
typedef vector<int> vi;
typedef queue<int> qi;
typedef set<int> si;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define fr(i, a, b) for(i=a; i<b; i++)
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define sortv(a) sort(a.begin(), a.end())
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define sqr(x) ((x) * (x))
#define sz(x) ((ll)x.size())
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
int i=0;
int t, n, m, k, s, d, u, v, length, upto, ans;
struct node{
int v, d;
node(int a, int b){
v=a; d=b;
}
};
vector<node> adj[10001], rev[10001];
int da[10001], db[10001];
int main(){
scanf("%d", &t);
while(t--){
scanf("%d%d%d%d%d", &n, &m, &k, &s, &d);
fr(i, 0, n){
da[i]=INT_MAX;
db[i]=INT_MAX;
adj[i].clear();
rev[i].clear();
}
fr(i, 0, m){
scanf("%d%d%d", &u, &v, &length);
u--; v--;
adj[u].pb(node(v, length));
rev[v].pb(node(u, length));
}
set<pair<int, int> > q;
s--; d--;
q.insert(mp(0, s));
while(!q.empty()){
u=q.begin()->second;
upto=q.begin()->first;
q.erase(q.begin());
fr(i, 0, sz(adj[u])){
v=adj[u][i].v;
length=adj[u][i].d;
if(upto+length<da[v]){
q.erase(mp(da[v], v));
da[v]=upto+length;
q.insert(mp(da[v], v));
}
}
}
q.insert(mp(0, d));
while(!q.empty()){
u=q.begin()->second;
upto=q.begin()->first;
q.erase(q.begin());
fr(i, 0, sz(rev[u])){
v=rev[u][i].v;
length=rev[u][i].d;
if(upto+length<db[v]){
q.erase(mp(db[v], v));
db[v]=upto+length;
q.insert(mp(db[v], v));
}
}
}
ans=db[s];
fr(i, 0, k){
scanf("%d%d%d", &u, &v, &length);
u--; v--;
if(da[u]!=INT_MAX && db[v]!=INT_MAX){
ans=min(ans, da[u]+length+db[v]);
}
if(da[v]!=INT_MAX && db[u]!=INT_MAX){
ans=min(ans, da[v]+length+db[u]);
}
}
if(ans==INT_MAX){
printf("-1\n");
continue;
}
printf("%d\n", ans);
}
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdHlwZWRlZiBsb25nIGxvbmcgaW50IGxsOwp0eXBlZGVmIGxvbmcgZG91YmxlIGxkOwp0eXBlZGVmIHZlY3RvcjxsbD4gdmw7CnR5cGVkZWYgcXVldWU8bGw+IHFsOwp0eXBlZGVmIHNldDxsbD4gc2w7CnR5cGVkZWYgdmVjdG9yPGludD4gdmk7CnR5cGVkZWYgcXVldWU8aW50PiBxaTsKdHlwZWRlZiBzZXQ8aW50PiBzaTsKCiNkZWZpbmUgcGIgcHVzaF9iYWNrCiNkZWZpbmUgbGIgbG93ZXJfYm91bmQKI2RlZmluZSB1YiB1cHBlcl9ib3VuZAojZGVmaW5lIG1wIG1ha2VfcGFpcgojZGVmaW5lIGZyKGksIGEsIGIpIGZvcihpPWE7IGk8YjsgaSsrKQojZGVmaW5lIG1zZXQoYSwgYikgbWVtc2V0KGEsIGIsIHNpemVvZihhKSkKI2RlZmluZSB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