#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <climits>
#include <queue>
#include <fstream>
#include <sstream>
#include <math.h>
#include <list>
using namespace std;
using ll = long long;
struct node
{
int tomDist = -1;
int branch = -1;
int wrongNode = -1;
};
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, t, j, h;
cin >> n >> m >> t >> j >> h;
t--; h--;
vector<node> nodes(n, node());
vector<vector<int>> tomEdges(n, vector<int>());
vector<vector<int>> jerryEdges(n, vector<int>());
vector<bool> visited(n, false);
vector<bool> accessibleByTom(n, false);
for (int i = 0; i < m; i++)
{
int a, b, w;
cin >> a >> b >> w;
a--; b--;
if (w == 2)
{
tomEdges[a].push_back(b);
tomEdges[b].push_back(a);
}
jerryEdges[a].push_back(b);
jerryEdges[b].push_back(a);
}
queue<int> tomQueue;
tomQueue.push(t);
nodes[t].tomDist = 0;
set<int> validBranches;
accessibleByTom[t] = true;
while (!tomQueue.empty())
{
int next = tomQueue.front();
tomQueue.pop();
for (int neigh : tomEdges[next])
{
if (neigh != h && nodes[neigh].tomDist == -1)
{
nodes[neigh].tomDist = nodes[next].tomDist + 1;
tomQueue.push(neigh);
accessibleByTom[neigh] = true;
}
}
}
queue<int> q;
q.push(h);
visited[h] = true;
int branch = 0;
while (!q.empty())
{
int next = q.front();
q.pop();
if (nodes[next].tomDist != -1 && nodes[next].branch == -1)
{
nodes[next].branch = branch;
branch++;
nodes[next].wrongNode = next;
}
bool isBranch = nodes[next].branch != -1;
for (int neigh : jerryEdges[next])
{
if (!visited[neigh])
{
if (isBranch)
{
nodes[neigh].branch = nodes[next].branch;
nodes[neigh].tomDist = max(0, nodes[next].tomDist - 1);
nodes[neigh].wrongNode = nodes[next].wrongNode;
}
q.push(neigh);
visited[neigh] = true;
}
else
{
if (!accessibleByTom[next] && !accessibleByTom[neigh] && nodes[neigh].branch != nodes[next].branch)
{
if (nodes[next].branch != -1)
{
validBranches.insert(nodes[next].branch);
}
if (nodes[neigh].branch != -1)
{
validBranches.insert(nodes[neigh].branch);
}
}
}
}
}
for (int i = 0; i < j; i++)
{
int nextNode;
cin >> nextNode;
nextNode--;
if (nodes[nextNode].branch == -1)
{
cout << "0\n";
}
else
{
if (validBranches.count(nodes[nextNode].branch) != 0)
{
cout << "0\n";
}
else
{
if (nodes[nextNode].tomDist > 0)
{
cout << "0\n";
}
else
{
cout << nodes[nextNode].wrongNode + 1 << "\n";
}
}
}
}
}