#include <iostream>
#include <algorithm>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <cstring>

using namespace std;
typedef pair<int, int> pii;

bool visited[10005];
int ni;
int dist[16][16];
int dp[1024][16];

int dfs(int z, int c) {
	if (dp[z][c] != -1) return dp[z][c];
	if (__builtin_popcount(z) == 1) {
		return dp[z][c] = dist[0][c];
	}
	int ans = 1000000000;
	for (int i = 0; i < ni; i++) {
		if (i == c) continue;
		if (z & (1 << i)) {
			ans = min(ans, dfs(z - (1<<c), i) + dist[i][c]);
		}
	}
	return dp[z][c] = ans;
}

vector<pii> adj[10005];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int ncase; cin >> ncase; 
	for (int csnum = 1; csnum <= ncase; csnum++) {
		int n, m; cin >> n >> m;
		for (int i = 0; i < n; i++) adj[i].resize(0);
		for (int i = 0; i < m; i++) {
			int a, b, len; cin >> a >> b >> len;
			adj[a].push_back(pii(b, len));
			adj[b].push_back(pii(a, len));
		}

		cin >> ni;
		map<int, int> locs;
		for (int i = 0; i < ni; i++) {
			int p; cin >> p;
			locs[p]++;
		}
		locs[0] += 0;
		ni = locs.size();
		int p[ni]; int psz = 0;
		for (auto it = locs.begin(); it != locs.end(); ++it) {
			p[psz++] = it->first;
		}

		//for (int i = 0; i < ni; i++) cerr << i << " " << p[i] << " " << locs[p[i]] << endl;

		for (int i = 0; i < ni; i++) {
			dist[i][i] = 0;
			for (int j = i+1; j < ni; j++) {
				dist[i][j] = 2000000;
				memset(visited, 0, sizeof visited);
				priority_queue<pii> q;
				q.push(pii(0, p[i]));
				while (!q.empty()) {
					pii entry = q.top(); q.pop();
					int d = -entry.first;
					int u = entry.second;
					if (visited[u]) continue;
					visited[u] = true;
					if (u == p[j]) {
						dist[i][j] = d;
						break;
					}
					for (pii nxt : adj[u]) {
						q.push(pii(-d-nxt.second, nxt.first));
					}
				}
				dist[j][i] = dist[i][j];

				//cerr << i << " " << j << " " << dist[i][j] << endl;
			}
		}

		int air; cin >> air;
		int ans = 0;
		memset(dp, -1, sizeof dp);
		for (int z = 1; z < (1<<ni); z += 2) {
			int zz = dfs(z, 0);
			if (zz <= air) {
				int cnt = 0;
				for (int i = 0; i < ni; i++) {
					if (z & (1 << i)) {
						cnt += locs[p[i]];
					}
				}
				ans = max(ans, cnt);
			}
		}
		cout << ans << endl;
	}
}