#include<bits/stdc++.h>
using namespace std;
const int MaxN = 400010, MaxM = 400010;
struct edge
{
int to, dis, next;
};
edge e[MaxM];
long long head[MaxN], dis[MaxN], cnt, a[MaxN];
bool vis[MaxN];
int n, m, s, w;
inline void add_edge( int u, int v, int d )
{
cnt++;
e[cnt].dis = d;
e[cnt].to = v;
e[cnt].next = head[u];
head[u] = cnt;
}
struct node
{
int dis;
int pos;
bool operator <( const node &x )const
{
return x.dis < dis;
}
};
std::priority_queue<node> q;
inline void dijkstra()
{
dis[s] = 0;
q.push( ( node ){0, s} );
while( !q.empty() )
{
node tmp = q.top();
q.pop();
int x = tmp.pos, d = tmp.dis;
if( vis[x] )
continue;
vis[x] = 1;
for( int i = head[x]; i; i = e[i].next )
{
int y = e[i].to;
if( dis[y] > dis[x] + e[i].dis )
{
dis[y] = dis[x] + e[i].dis;
if( !vis[y] )
{
q.push( ( node ){dis[y], y} );
}
}
}
}
}
int main()
{
scanf( "%d%d%d", &n, &m, &s, &w);
for(int i = 1; i <= n; ++i)dis[i] = LONG_LONG_MAX;
for( register int i = 0; i < m; ++i )
{
register int u, v, d;
scanf( "%d%d%d", &u, &v, &d );
add_edge( u, v, d );
}
dijkstra();
for(register int i = 0; i < w; ++i)
{
printf( "%d", 1 );
scanf( "%d", &a[i] );
}
for(register int i = 0; i < w; ++i)
{
printf( "%d\n", dis[a[i]] );
}
return 0;
}