#include <stdio.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <complex>
#include <assert.h>
#define MAX_N 200005
#define INF 1000000000000000LL
using namespace std;
typedef long long ll;
int n;
set<int> parent[MAX_N];
int color[MAX_N];
struct Node
{
ll dist;
vector<int> adj;
vector<ll> weight;
};
Node graf[MAX_N];
bool mark[MAX_N];
struct pq_entry
{
ll node, dist;
bool operator <(const pq_entry &a) const
{
if (dist != a.dist) return (dist > a.dist);
return (node > a.node);
}
};
inline void Dijkstra(int source)
{
priority_queue<pq_entry> pq;
pq_entry P;
for (int i=0;i<n;i++) {
mark[i] = 0; parent[i].clear();
if (i == source)
{
graf[i].dist = 0;
P.node = i;
P.dist = 0;
pq.push(P);
}
else graf[i].dist = INF;
}
while (!pq.empty())
{
pq_entry curr = pq.top();
pq.pop();
int nod = curr.node;
ll dis = curr.dist;
for (int i=0;i<graf[nod].adj.size();i++)
{
if (!mark[graf[nod].adj[i]])
{
int nextNode = graf[nod].adj[i];
if(dis + graf[nod].weight[i] == graf[nextNode].dist){
parent[nextNode].insert(nod);
}
else if ((dis + graf[nod].weight[i]) < graf[nextNode].dist) {
parent[nextNode].clear(); parent[nextNode].insert(nod);
graf[nextNode].dist = dis + graf[nod].weight[i];
P.node = nextNode;
P.dist = graf[nextNode].dist;
pq.push(P);
}
}
}
mark[nod] = true;
}
}
int S[MAX_N], mark_pa[MAX_N], m;
set<int> ss;
vector<int> ans_v;int cnt;
int dfs(int u, int pa) {
cnt++;
//if(cnt >= m) assert(0);
int ans = 0; if(ss.find(u) != ss.end()) ans++;
int maxi = 0, x = u;
color[u] = 1;
for(set<int> :: iterator it = parent[u].begin(); it != parent[u].end(); it++) {
int v = *it;
if(color[v] == 1) assert(0);
int num = 0;
if(color[v] == 2) num = mark_pa[v];
else num = dfs(v, u);
//if(num > maxi) maxi = num, x = v;
ans = ans + num;
}
color[u] = 2;
mark_pa[u] = ans;
return ans;
}
void _dfs(int u) {
ans_v.push_back(u);
int maxi = -1, x = u;
for(set<int> :: iterator it = parent[u].begin(); it != parent[u].end(); it++) {
int v = *it;
if(mark_pa[v] > maxi) maxi = mark_pa[v], x = v;
}
if(maxi > 0) _dfs(x);
}
void solve() {
int u, v; ll c; ss.clear();ans_v.clear(); cnt = 0;
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++) color[i] = 0, mark_pa[i] = 0;
for(int i = 0; i < n; i++) graf[i].adj.clear(), graf[i].weight.clear();
for(int i = 0; i < m; i++) {
scanf("%d %d %lld", &u, &v, &c); --u, --v;
graf[u].adj.push_back(v); graf[v].adj.push_back(u);
graf[u].weight.push_back(c); graf[v].weight.push_back(c);
}
int total; scanf("%d", &total);
for(int i = 0; i < total; i++) scanf("%d", &S[i]);
for(int i = 0; i < total; i++) ss.insert(--S[i]);
Dijkstra(S[0]);
int start = S[0];
for(int i = 0; i < total; i++) if(graf[S[i]].dist > graf[start].dist) start = S[i];
Dijkstra(start);
int other = start;
for(int i = 0; i < total; i++) if(graf[S[i]].dist > graf[other].dist) other = S[i];
/*cout << start << " " << other << endl;
for(int i = 0; i < n; i++) cout << graf[i].dist << " "; cout << endl;
cout << "set: ";
for(set<int> :: iterator it = ss.begin(); it != ss.end(); it++) {
cout << " " << *it;
} cout << endl;
for(int i = 0; i < n; i++) {
cout << "parent of " << i << ": ";
for(set<int> :: iterator it = parent[i].begin(); it != parent[i].end(); it++) {
cout << (*it) << " ";
}
cout << endl;
}*/
dfs(other, other);
//return;
_dfs(other);
int siz = ans_v.size();
printf("%d\n", siz);
assert((other == ans_v[0]) && (start == ans_v[siz - 1]));
for(int i = 0; i < siz; i++) printf("%d ", ans_v[i] + 1); printf("\n");
//for(int i = 0; i < n; i++) cout << graf[i].dist << " "; cout << endl;
}
int main() {
int t = 1; scanf("%d", &t);
for(int i = 0; i < t; i++) {
//if(i == 1) assert(0);
solve();
}
}