#include <bits/stdc++.h>
using namespace std;
#define N 50005

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef long long ll;

vvii G;
ll D[N];
int v[N];
int pp[N];

int main() {
  ios::sync_with_stdio(0);
  int k;
  cin >> k;
  int n, m, t, s, g, h;
  while (k--) { 
    cin >> n >> m >> t;
    cin >> s >> g >> h;
    s--; g--; h--;

    vvii gg(n);
    memset(D, 0x7e, sizeof (D));
    memset(v, 0, sizeof (v));
    memset(pp, 0, sizeof (pp));
    D[s] = 0;

    for (int i = 0; i < m; i++) {
      int a, b, d;
      cin >> a >> b >> d;
      a--; b--;
      if ((a == g && b == h) || (b == g && a == h)) {
        gg[a].push_back({b, d * 32 - 1});
        gg[b].push_back({a, d * 32 - 1});
      } else {
        gg[a].push_back({b, d * 32});
        gg[b].push_back({a, d * 32});
      }
    }
    priority_queue<pii> q;
    q.push({0, s});

    while (!q.empty()) {
      auto p = q.top();
      q.pop();
      int node = p.second;
      if (v[node]) {
        continue;
      }
      v[node] = 1;
      for (auto n : gg[node]) {
        int nei = n.first;
        int dist = n.second;
        if (!v[nei]) {
          if (D[node] + dist < D[nei]) {
            D[nei] = D[node] + dist;
            pp[nei] = node;
          }
          q.push({-D[nei], nei});
        }
      }
    }
    int dgh = 0;
    for (auto e : gg[g]) {
      if (e.first == h) {
        dgh = e.second; 
      }
    }
    set<int> r;
    for (int i = 0; i < t; i++) {
      int x;
      cin >> x;
      x--;
      
      if (D[x] % 2 == 1) {
        r.insert(x + 1);
      }
    }
    for (auto e : r) {
      cout << e << ' ';
    }
    cout << '\n';
  }
  return 0;
}