#include<bits/stdc++.h>
using namespace std;
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
int n,m,t,qs,e;
struct edg {
int to,w,ind;
};
vector<edg> adj[30001];
int st1[30001], dfs_low[30001], dfs_num[30001], ind=0, bc[100001], bcind=1, dst_t[30001], dst_e[30001], st2[30001], art[30001];
stack<int> st;
vector<pair<int,int>> edgs;
void dfs1(int x, int par_e=-1) {
st1[x]=1;
dfs_low[x]=dfs_num[x]=++ind;
int ch=0;
for(edg i:adj[x]) {
if(par_e==i.ind) {
continue ;
}
if(st1[i.to]) {
dfs_low[x]=min(dfs_low[x], dfs_num[i.to]);
if(dfs_num[x]>dfs_num[i.to]) st.push(i.ind);
}else {
ch++;
st.push(i.ind);
dfs1(i.to, i.ind);
if((ch>1 && par_e==-1) || (dfs_low[i.to]>=dfs_num[x])) {
art[x]=1;
while(st.top()!=i.ind) {
//~ cerr<<edgs[st.top()].xx<<" "<<edgs[st.top()].yy<<"\n";
bc[st.top()]=bcind;
st.pop();
}
//~ cerr<<edgs[st.top()].xx<<" "<<edgs[st.top()].yy<<"\n";
//~ cerr<<"===\n";
bc[st.top()]=bcind++;
st.pop();
}
dfs_low[x]=min(dfs_low[x], dfs_low[i.to]);
}
}
}
int ans[30001];
int ac;
void dfs2(int x, int par_e, int idx, int tav) {
//~ cerr<<x<<" "<<idx<<" "<<tav<<"\n";
if(tav<=0) {
//~ cerr<<x<<" -> "<<idx<<"\n";
ans[x]=idx;
}
st2[x]=1;
for(auto i:adj[x]) {
if(dst_e[i.to]!=dst_e[x]+1) continue ;
if(x==e) {
if(bc[i.ind]!=ac) {
continue ;
}
dfs2(i.to, i.ind, idx, tav);
}else {
if(!st2[i.to]) {
if(bc[i.ind]==bc[par_e]) {
dfs2(i.to, i.ind, idx, tav-1);
}else {
if(dst_t[x]<=tav)
dfs2(i.to, i.ind, x, dst_t[x]-1);
else
dfs2(i.to, i.ind, idx, tav-1);
}
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin>>n>>m>>t>>qs>>e;
for(int i=0;i<m;++i) {
int a,b,c;
cin>>a>>b>>c;
adj[a].pb(edg{b,c,i});
adj[b].pb(edg{a,c,i});
edgs.pb(mp(a,b));
}
dfs1(e);
while(!st.empty()) {
//~ cerr<<edgs[st.top()].xx<<" "<<edgs[st.top()].yy<<"\n";
bc[st.top()]=bcind;
st.pop();
}
//~ cerr<<"===\n";
bcind++;
queue<int> q;
for(int i=1;i<=n;++i) dst_t[i]=1e9;
q.push(t);
st2[t]=1;
dst_t[t]=0;
while(!q.empty()) {
auto fr=q.front();q.pop();
for(auto i:adj[fr]) {
if(i.w==2 && !st2[i.to] && i.to!=e) {
dst_t[i.to]=dst_t[fr]+1;
st2[i.to]=1;
q.push(i.to);
}
}
}
q.push(e);
dst_e[e]=0;
memset(st2, 0, sizeof st2);
st2[e]=1;
while(!q.empty()) {
auto fr=q.front();q.pop();
for(auto i:adj[fr]) {
if(!st2[i.to]) {
dst_e[i.to]=dst_e[fr]+1;
st2[i.to]=1;
q.push(i.to);
}
}
}
memset(st2, 0, sizeof st2);
vector<int> volt(n+1);
for(auto i:adj[e]) {
if(!volt[bc[i.ind]]) {
//cerr<<i.to<<"\n";
//cerr<<bc[i.ind]<<"what\n";
ac=bc[i.ind];
dfs2(e, -1, 1e9, 1e9);
volt[bc[i.ind]]=1;
}
}
for(int i=0;i<qs;++i) {
int x;
cin>>x;
cout<<ans[x]<<"\n";
}
}