#include <bits/stdtr1c++.h>

using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef complex<ld> pt;

const int N = 2005;
struct edge {
	int v, w;
};

vector<edge> G[N];
int dist[N], dist2[N], dist3[N];

int* d;
struct comp {
	bool operator()(int l, int r) const {
		if (d[l] == d[r]) return l < r;
		return d[l] < d[r];
	}
};

void dijkstra(int s, int* dd) {
	d = dd;
	d[s] = 0;
	set<int> q({s});
	while (!q.empty()) {
		int u = *q.begin();
		q.erase(q.begin());
		for (auto e : G[u]) {
			if (d[e.v] > d[u] + e.w) {
				q.erase(e.v);
				d[e.v] = d[u] + e.w;
				q.insert(e.v);
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(0);
	int T; cin >> T;
	while (T--) {
		int n, m, t; cin >> n >> m >> t;
		int s, g, h; cin >> s >> g >> h;
		s--, g--, h--;
		
		for (int i = 0; i < N; i++) {
			G[i].clear();
		}
		
		int W;
		for (int i = 0; i < m; i++) {
			int u, v, w; cin >> u >> v >> w;
			u--; v--;
			
			if (min(u, v) == min(g, h) && max(u, v) == max(g, h)) W = w;
			G[u].push_back({v, w});
			G[v].push_back({u, w});
		}
		//cerr << W << endl;
		
		memset(dist, 0x3f, sizeof dist);
		memset(dist2, 0x3f, sizeof dist2);
		memset(dist3, 0x3f, sizeof dist3);
		dijkstra(s, dist);
		dijkstra(g, dist2);
		dijkstra(h, dist3);
		
		vector<int> dest;
		for (int i = 0; i < t; i++) {
			int x; cin >> x;
			x--;
			dest.push_back(x);
			//cerr << s << " " << x << " " << dist[x] << " " << dist[g] + dist3[x] + W << " " << dist[h] + dist2[x] + W << endl;
		}
		sort(dest.begin(), dest.end());
		
		for (int x : dest) {
			if (dist[g] + dist3[x] + W == dist[x]) cout << x+1 << " ";
			if (dist[h] + dist2[x] + W == dist[x]) cout << x+1 << " ";
		}
		cout << endl;
	}
	return 0;
}