// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
using namespace std;
// mylittledoge
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
int T;
cin >> T;
for(int t =0; t < T; t++) {
int N,st,G,S,M,K;
cin >> N >> st >> G >> S >> K;
vector< vector< pair<int,int> > > E(N*(S+1)+2);
vector< vector<int> > rev(N*(S+1)+2);
// (S+1)*N: source
// (S+1)*N+1: sink
// numbered time*N+vertex
// from source
rev[(S+1)*N].push_back(E[st-1].size());
rev[st-1].push_back(E[(S+1)*N].size());
E[(S+1)*N].push_back(make_pair(st-1,G));
E[st-1].push_back(make_pair((S+1)*N,0));
// to sink
for(int i =0; i < K; i++) {
int a;
cin >> a;
a--;
rev[S*N+a].push_back(E[(S+1)*N+1].size());
rev[(S+1)*N+1].push_back(E[S*N+a].size());
E[S*N+a].push_back(make_pair((S+1)*N+1,1000));
E[(S+1)*N+1].push_back(make_pair(S*N+a,0));}
// self-loops
for(int i =0; i < S*N; i++) {
rev[i].push_back(E[i+N].size());
rev[i+N].push_back(E[i].size());
E[i].push_back(make_pair(i+N,1000));
E[i+N].push_back(make_pair(i,0));}
// roads
cin >> M;
for(int i =0; i < M; i++) {
int u,v,p,tt;
cin >> u >> v >> p >> tt;
u--, v--;
for(int j =0; j <= S-tt; j++) {
rev[j*N+u].push_back(E[(j+tt)*N+v].size());
rev[(j+tt)*N+v].push_back(E[j*N+u].size());
E[j*N+u].push_back(make_pair((j+tt)*N+v,p));
E[(j+tt)*N+v].push_back(make_pair(j*N+u,0));}
}
int f =0;
N =E.size();
queue<int> q;
while(true) {
vector< pair<int,int> > ako(N,make_pair(-1,-1));
vector<int> F(N,G+1);
q.push(N-2);
while(!q.empty()) {
for(int i =0; i < E[q.front()].size(); i++) if(ako[E[q.front()][i].ff].ff == -1 && E[q.front()][i].ss > 0) {
F[E[q.front()][i].ff] =min(F[q.front()],E[q.front()][i].ss);
ako[E[q.front()][i].ff] =make_pair(q.front(),i);
q.push(E[q.front()][i].ff);}
q.pop();}
// cout << F[N-1] << ".\n";
if(F[N-1] == G+1) break;
f +=F[N-1];
int akt =N-1;
while(akt != N-2) {
// cout << akt << endl;
int u =akt, v =ako[akt].ff, y =ako[akt].ss;
// cout << u << " " << v << "\n";
int x =rev[v][y];
E[u][x].ss +=F[N-1];
E[v][y].ss -=F[N-1];
akt =v;}
}
cout << f << "\n";}
return 0;}
// look at my code
// my code is amazing
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDxtYXA+CiNpbmNsdWRlIDxxdWV1ZT4KI2luY2x1ZGUgPHN0YWNrPgojaW5jbHVkZSA8bGlzdD4KI2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9tYW5pcD4KI2RlZmluZSBkaWJzIHJlc2VydmUKI2RlZmluZSBPVkVSOTAwMCAxMjM0NTY3ODkwCiNkZWZpbmUgQUxMX1RIRShDQUtFLExJRSkgZm9yKGF1dG8gTElFID1DQUtFLmJlZ2luKCk7IExJRSAhPSBDQUtFLmVuZCgpOyBMSUUrKykKI2RlZmluZSB0aXNpYyA0NwojZGVmaW5lIHNvY2xvc2UgMWUtOAojZGVmaW5lIGNob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