#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std; using namespace placeholders;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector< int > VI;
typedef vector< vector< int > > VVI;
typedef vector< string > VS;
typedef stringstream SS;
typedef pair< int, int > PII;
typedef vector< pair< int, int > > VPII;
#define VT( T ) vector< T >
#define VVT( T ) vector< vector< T > >
#define LIM( T ) numeric_limits< T >

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; };
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &e : c )
#define ALL( c ) ( c ).begin(), ( c ).end()
#define AALL( a, t ) ( t* )a, ( t* )a + sizeof( a ) / sizeof( t )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + p, ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

constexpr LL INF = LIM( LL )::max() / 2;

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int N, M, K, P;
	cin >> N >> M >> K >> P;
	--P;

	VT( VPII ) G( N );
	REP( i, M )
	{
		int a, b, c;
		cin >> a >> b >> c;
		--a, --b;

		G[a].EB( b, c );
		G[b].EB( a, c );
	}

	VI dropped( N ), deliver( N );
	REP( i, K )
	{
		int s, t;
		cin >> s >> t;
		--s, --t;

		dropped[s] |= 1 << i;
		deliver[t] |= 1 << i;
	}

	VVT( LL ) distances( 1 << 2 * K, VT( LL )( N, INF ) );
	distances[ dropped[P] | ( ( dropped[P] & deliver[P] ) << K ) ][P] = 0;

	typedef tuple< LL, int, int > State;
	priority_queue< State, VT( State ), greater< State > > que;
	que.EM( 0, dropped[P] | ( ( dropped[P] & deliver[P] ) << K ), P );

	while ( !que.empty() )
	{
		const LL dist = get<0>( que.top() );
		const int s = get<1>( que.top() );
		const int u = get<2>( que.top() );
		que.pop();

		if ( distances[s][u] < dist )
		{
			continue;
		}

		FOR( e, G[u] )
		{
			const int v = e.fst;
			const int c = e.snd;

			const int nhaving = ( s % ( 1 << K ) ) | dropped[v];
			const int ns = s | ( ( deliver[v] & nhaving ) << K ) | dropped[v];

			if ( distances[s][u] + c < distances[ ns ][v] )
			{
				que.EM( distances[ ns ][v] = dist + c, ns, v );
			}
		}
	}

	const LL res = *min_element( ALL( distances[ ( 1 << 2 * K ) - 1 ] ) );
	if ( res == INF )
	{
		cout << "Cannot deliver" << endl;
	}
	else
	{
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 34336