#include <bits/stdc++.h>
using namespace std;
void fjerry(int x, int d, bool visited[], set<int> hist, int pii, vector<vector<int>>& jerry, int n, set<int>& ctom)
{
visited[x] = true;
hist.insert(x);
pii++;
if (x == d) {
for (int i = 0; i < n; i++){
if(!hist.count(i)) ctom.erase(i);
}
}
else {
for(int i = 0; i < (int)jerry[x].size(); i++)
if (!visited[jerry[x][i]])
fjerry(jerry[x][i], d, visited, hist, pii, jerry,n,ctom);
}
pii--;
visited[x] = false;
hist.erase(x);
}
void route(int x, int d, bool visited[], int pii, vector<vector<int>>& map, int& l)
{
visited[x] = true;
pii++;
if (x == d && pii < l) l=pii;
else {
for(int i = 0; i < (int)map[x].size(); i++)
if (!visited[map[x][i]])
route(map[x][i], d, visited, pii, map, l);
}
pii--;
visited[x] = false;
}
int main(){
cin.tie(NULL); ios::sync_with_stdio(NULL);
int n, m, t, db, e;
cin >> n >> m >> t >> db >> e; e--; t--;
vector<vector<int>> tom; vector<vector<int>> jerry;
tom.assign(n, vector<int>());
jerry.assign(n, vector<int>());
for(int i=0; i<m; i++){
int a, b, c;
cin >> a >> b >> c;
a--; b--;
jerry[a].push_back(b);
jerry[b].push_back(a);
if(c==2&&b!=e&&a!=e){tom[a].push_back(b);tom[b].push_back(a);}
}
for(int i=0; i<db; i++){
int x; cin >> x; x--;
int pii=0;
bool* visited = new bool[n];
set<int> ctom;
set<int> hist;
for (int i = 0; i < n; i++){visited[i] = false; ctom.insert(i);}
fjerry(x,e,visited,hist,pii,jerry,n,ctom);
bool can=false;
int lena=100000000; int lenb=100000000;
for(auto it=ctom.begin(); it!=ctom.end(); it++){
int d = *it + 1;
pii=0;
for(int i = 0; i < n; i++){visited[i] = false;}
route(x,*it,visited,pii,jerry,lena);
pii=0;
for(int i = 0; i < n; i++){visited[i] = false;}
route(t,*it,visited,pii,tom,lenb);
if(lenb<=lena){cout << d << '\n'; can=true; break;}
}
if(!can) cout << '0' << '\n';
}
}