#include<iostream>
#include<vector>
#include<cstring>
#include<set>
#include<algorithm>

#define pii pair<int,int>

using namespace std;

// struct edge {
//     int cost, node;  
// };
const int infinity = 100000000;
int n,m,l,air;
vector<pii> adj[10000];
int ls[10];
int res[10000][10000];
bool seen[10000];


int dist[10000];
struct cmp {
    bool operator()(const int& u, const int& v) {
        if ( dist[u] == dist[v] ) return u < v;
        else return dist[u] < dist[v];
    }
};
void dijkstra( int s ) {
    for ( int v=0; v<n; v++ ) {
	dist[v] = infinity;
	res[s][v] = infinity;
    }
    dist[s] = 0;
    res[s][s] = 0;
    set<int, cmp> q;
    q.insert(s);
    while ( !q.empty() ) {
        int v = *q.begin();
        q.erase(q.begin());
        for ( pii x: adj[v] ) {//each edge e = (v, u) leaving v ) {
	    int u = x.first;
            if ( x.second + dist[v]< dist[u] ) {
                q.erase(u);
                dist[u] = dist[v] + x.second;
		res[s][u] = dist[v] + x.second;
                q.insert(u);
            }
        }
    }
}

bool recur(int bm, vector<int> &vec) {
	if(bm == 0) {
		int cost = 0;
		cost += res[0][vec[0]];
		cost += res[vec[vec.size()-1]][0];
		for(int i=0; i<vec.size()-1; i++) {
			cost+= res[vec[i]][vec[i+1]];
		}
		if(cost <= air) {
			return true;
		}
		else return false;
	}
	for(int i=0; i<l; i++) {
		if(bm & (1<<i)) {
			vec.push_back(ls[i]);
			if(recur(bm & ~(1<<i), vec)) {
				return true;
			}
			vec.pop_back();
		}
	}
	return false;
}

bool ok(int bm) {
	vector<int> vec;
	return recur(bm, vec);
}


int main(void) {
    int T; cin >> T;
    
    while(T--) {
        cin >> n >> m;
        for(int i=0; i<n; i++) {
            adj[i].clear();
        }
        for(int i=0; i<m; i++) {
            int u,v,c; cin >> u >> v >> c;
            adj[u].push_back({v,c});
            adj[v].push_back({u,c});
        }
        cin >> l;
        for(int i=0; i<l; i++) cin >> ls[i];
        cin >> air;
	dijkstra(0);
        for(int i=0; i<l; i++) {
       	    memset(seen, 0, sizeof seen);
	    dijkstra(ls[i]);
	}
/*
	for(int i=0; i<l; i++) {
		for(int j=0; j<n; j++) {
			cout << res[i][j] << " ";
		} cout << endl;
	}
I*/
	int ans = 0;
	for(int i=1; i<(1<<l); i++) {
		if(ok(i)) {
			ans = max(ans, __builtin_popcount(i));
		}
	}
	cout << ans << endl;
    }
    
    return 0;
}