#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    const int INF = 1<<28;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    const int MAX_N = 1000;
    const int MAX_CARD_STATES_N = 1<<(6*2);

    struct Edge {
        int to, cost;
        Edge(int to, int cost) : to(to), cost(cost) {}
    };

    int N, M, K, P;
    vector<vector<Edge>> G;
    vector<int> S, T;
    void input() {
        cin >> N >> M >> K >> P;
        P--;
        G.clear(); G.resize(N);
        for (int i = 0; i < M; i++) {
            int x, y, w; cin >> x >> y >> w;
            x--; y--;
            G[x].push_back(Edge(y, w));
            G[y].push_back(Edge(x, w));
        }
        S.clear(); S.resize(N, -1);
        T.clear(); T.resize(N, -1);
        for (int i = 0; i < K; i++) {
            int s, t; cin >> s >> t;
            s--; t--;
            S[s] = i;
            T[t] = i;
        }
    }

    int get(int k, int s) {
        int a = (s & (1 << (2*k))) >> (2*k);
        int b = (s & (1 << (2*k+1))) >> (2*k+1);
        return 2*b+a;
    }
    void set(int k, int v, int& s) {
        int a = v % 2;
        int b = v / 2;
        if (a == 0) {
            s &= (~(1 << (2*k)));
        } else {
            s |= (1 << (2*k));
        }
        if (b == 0) {
            s &= (~(1 << (2*k+1)));
        } else {
            s |= (1 << (2*k+1));
        }
    }

    struct State {
        int v, have, cost;
        State(int v, int have, int cost) : v(v), have(have), cost(cost) {}
    };
    bool operator<(const State& a, const State& b) {
        return a.cost > b.cost;
    }
    void solve() {
        static int D[MAX_N][MAX_CARD_STATES_N];
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < MAX_CARD_STATES_N; j++) {
                D[i][j] = INF;
            }
        }
        priority_queue<State> PQ;
        int init_have = 0;
        if (S[P] >= 0) set(S[P], 1, init_have);
        PQ.push(State(P, init_have, 0));
        D[P][init_have] = 0;
        while (not PQ.empty()) {
            State c = PQ.top(); PQ.pop();
            for (int i = 0; i < G[c.v].size(); i++) {
                State n = c;
                const Edge& e = G[c.v][i];
                n.v = e.to;
                n.cost = c.cost + e.cost;
                if (S[n.v] >= 0) {
                    int h = get(S[n.v], n.have);
                    if (h == 0) set(S[n.v], 1, n.have); // ???????????£?????????????????£????????°?????¬??????????£°
                }
                if (T[n.v] >= 0) {
                    int h = get(T[n.v], n.have);
                    if (h == 1) set(T[n.v], 2, n.have); // ?¬????????????????????????????????????????????????????
                }
                if (D[n.v][n.have] > n.cost) {
                    D[n.v][n.have] = n.cost;
                    PQ.push(n);
                }
            }
        }
        int finished_state = 0;
        for (int i = 0; i < K; i++) {
            set(i, 2, finished_state);
        }
        int ans = INF;
        for (int i = 0; i < N; i++) {
            ans = min(ans, D[i][finished_state]);
        }
        if (ans == INF) {
            cout << "Cannot deliver" << endl;
        } else {
            cout << ans << endl;
        }
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 19824