#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using OS = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long

const int N = 1e5 + 5;
ll n, m, k, x, y, z, q, p[N], rnk[N], dist[N], out[N];
vector<vector<pair<ll, ll>>> v(N);
vector<pair<ll, pair<ll, ll>>> adj;
set<ll> se[N];

void dij() {
    memset(dist, 63, sizeof dist);
    set<pair<ll, ll>> q;
    for (int i = 1; i <= k; i++) {
        q.insert({0, i});
        dist[i] = 0;
        p[i] = i;
    }
    while (!q.empty()) {
        x = q.begin()->second;
        q.erase(q.begin());
        for (auto i : v[x]) {
            if (dist[i.first] > dist[x] + i.second) {
                q.erase({dist[i.first], i.first});
                dist[i.first] = dist[x] + i.second;
                q.insert({dist[i.first], i.first});
                p[i.first] = p[x];
            }
        }
    }
}

int f(int x) {
    return x == p[x] ? x : p[x] = f(p[x]);
}

void con(ll x, ll y, ll w) {
    x = f(x), y = f(y);
    if (x == y) return;
    if (rnk[x] < rnk[y]) swap(x, y);
    p[y] = x;
    rnk[x] += rnk[y];

    if (se[x].size() < se[y].size()) se[x].swap(se[y]);
    for (auto i : se[y]) {
        if (se[x].count(i)) {
            se[x].erase(i);
            out[i] = w;
        } else {
            se[x].insert(i);
        }
    }
}

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

    cin >> n >> m >> k >> q;
    while (m--) {
        cin >> x >> y >> z;
        v[x].push_back({y, z});
        v[y].push_back({x, z});
    }

    dij();

    for (int i = 1; i <= n; i++) {
        for (auto j : v[i]) {
            if (p[j.first] != p[i]) {
                adj.push_back({dist[j.first] + dist[i] + j.second, {p[j.first], p[i]}});
            }
        }
    }
    sort(adj.begin(), adj.end());
    iota(p, p + N, 0);

    for (int i = 0; i < q; i++) {
        cin >> x >> y;
        se[x].insert(i);
        se[y].insert(i);
    }

    for (auto e : adj) {
        x = e.second.first;
        y = e.second.second;
        z = e.first;
        if (f(x) == f(y)) continue;
        con(x, y, z);
    }

    for (int i = 0; i < q; i++) cout << out[i] << '\n';

    return 0;
}