#include <bits/stdtr1c++.h>
using namespace std;

typedef pair<int,int> pii;

const int dx[4] = {1,-1,0,0};
const int dy[4] = {0,0,1,-1};

vector<pii> adj[2000];
bool vis[2000];
int mn[2000];

int main() {
  ios::sync_with_stdio(0);
  int T; cin >> T;
  while (T--) {
    int n, m, t, s, g, h;
    cin >> n >> m >> t >> s >> g >> h;
    --s; --g; --h;
    int e;
    for (int i = 0; i < n; i++)
      adj[i].clear();
    for (int i = 0; i < m; i++) {
      int a, b, d; cin >> a >> b >> d;
      --a; --b;
      if ((a == g && b == h) || (a == h && b == g))
        e = d;
      adj[a].push_back(make_pair(b,d));
      adj[b].push_back(make_pair(a,d));
    }
    set<int> S;
    for (int i = 0; i < t; i++) {
      int x; cin >> x; --x;
      memset(vis, 0, sizeof vis);
      for (int j = 0; j < n; j++)
        mn[j] = 0x3f3f3f3f;
      mn[s] = 0;
      priority_queue<pii> pq;
      pq.push(make_pair(0,s));
      while (pq.size()) {
        pii f = pq.top();
        pq.pop();
        if (f.second == x)
          break;
        if (vis[f.second])
          continue;
        vis[f.second] = true;
        for (int j = 0; j < adj[f.second].size(); j++) {
          int C = -f.first+adj[f.second][j].second;
          int u = adj[f.second][j].first;
          if (!vis[u] && mn[u] > C) {
            mn[u] = C;
            pq.push(make_pair(-C,u));
          }
        }
      }
      queue<int> q;
      q.push(x);
      memset(vis, 0, sizeof vis);
      vis[x] = true;
      while (q.size()) {
        int f = q.front();
        q.pop();
        for (int j = 0; j < adj[f].size(); j++) {
          int C = adj[f][j].second;
          int u = adj[f][j].first;
          if (!vis[u] && mn[f] == C+mn[u]) {
            if ((f == g && u == h) || (u == g && f == h)) {
              S.insert(x+1);
              goto VELOCIRAPTOR;
            }
            q.push(u);
          }
        }
      }
VELOCIRAPTOR:
      ;
    }
    bool first = true;
    for (int ss : S) {
      if (first)
        first = false;
      else
        cout << " ";
      cout << ss;
    }
    cout << "\n";
  }
  return 0;
}