#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3;
struct Edge
{
int to,w,next;
}edge[maxn];
int head[maxn], cnt = 0;
void add_edge(int u, int to, int w)
{
edge[cnt].to = to;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
}
int card[maxn]={},dis[maxn],visNode[maxn],visCard[maxn];
int n,m,k,c;
int ans = 0x3f3f3f3f;
void dfs(int u, int pp)
{
if(u == c)
{
ans = min(ans, pp);
return;
}
for(int i = head[u];i!=-1;i=edge[i].next)
{
int to = edge[i].to;
int w = edge[i].w;
int cardValue = card[w];
if(visNode[to] == 0)
{
visCard[w] = 1;
visNode[to] = 1;
card[w] = 0;
dfs(to,pp + cardValue);
card[w] = cardValue;
visNode[to] = 0;
}
}
}
int main()
{
while(cin>>n>>m>>k>>c)
{
for(int i = 0;i<maxn;i++)
{
ans = 0x3f3f3f3f;
dis[i] = 0x3f3f3f3f;
card[i] = 0;
head[i] = -1;
visNode[i] = 0;
visCard[i] = 0;
memset(edge,0,sizeof(edge));
}
for(int i = 0;i<m;i++)
{
int u,v,w;
cin>>u>>v>>w;
add_edge(u,v,w);
}
for(int i = 0;i<k;i++)
{
int o ,p;
cin>>o>>p;
card[o] = p;
}
dfs(1,0);
cout<<ans<<endl;
}
return 0;
}