#include <bits/stdc++.h>
using namespace std;
const long long MXN = 3e5 + 10;
const long long INF = 1e18;
long long n, m, k, q, now;
long long par[MXN], SZ[MXN], dis[MXN], C[MXN], ANS[MXN];
vector<pair<long long, long long>> G[MXN], Q[MXN];
vector<pair<pair<long long, long long>, long long>> E;
vector<pair<long long, pair<long long, long long>>> E2;
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
map<pair<long long, long long>, long long> mp;
set<long long> st[MXN];
bool vis[MXN];
void init() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    SZ[i] = 1;
    st[i].insert(i);
    dis[i] = INF;
    ANS[i] = INF;
  }
  return;
}
long long Find(long long u) {
  return (u == par[u] ? u : par[u] = Find(par[u]));
}
bool Union(long long u, long long v) {
  long long p1 = Find(u), p2 = Find(v);
  if (p1 == p2) return 0;
  if (SZ[p1] < SZ[p2]) {
    swap(p1, p2);
  }
  SZ[p1] += SZ[p2];
  par[p2] = p1;
  for (auto u : st[p2]) {
    for (auto Pr : Q[u]) {
      long long v = Pr.first, id = Pr.second;
      if (st[p1].find(v) != st[p1].end()) {
        ANS[id] = min(ANS[id], now);
      }
    }
  }
  for (auto u : st[p2]) {
    st[p1].insert(u);
  }
  st[p2].clear();
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k >> q;
  init();
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    G[u].push_back({v, w});
    G[v].push_back({u, w});
    E.push_back({{u, v}, w});
  }
  for (int i = 1; i <= k; i++) {
    dis[i] = 0;
    pq.push({0, i});
    C[i] = i;
  }
  for (int i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    Q[a].push_back({b, i});
    Q[b].push_back({a, i});
  }
  while (!pq.empty()) {
    long long u = pq.top().second, cost = pq.top().first;
    pq.pop();
    if (vis[u]) continue;
    vis[u] = 1;
    for (pair<long long, long long> PR : G[u]) {
      long long v = PR.first, w = PR.second;
      if (!vis[v] && dis[v] > cost + w) {
        dis[v] = cost + w;
        pq.push({dis[v], v});
        C[v] = C[u];
      }
    }
  }
  for (int i = 0; i < m; i++) {
    long long u = E[i].first.first, v = E[i].first.second, w = E[i].second;
    long long c1 = C[u], c2 = C[v];
    if (c1 < c2) swap(c1, c2);
    if (c1 != c2) {
      if (mp[{c1, c2}] == 0) {
        mp[{c1, c2}] = w + dis[u] + dis[v];
      } else {
        mp[{u, v}] = min(mp[{u, v}], w + dis[u] + dis[v]);
      }
    }
  }
  std::map<pair<long long, long long>, long long>::iterator itr = mp.begin();
  while (itr != mp.end()) {
    long long u = itr->first.first, v = itr->first.second, w = itr->second;
    E2.push_back({w, {u, v}});
    itr++;
  }
  sort(E2.begin(), E2.end());
  for (int i = 0; i < E2.size(); i++) {
    long long u = E2[i].second.first, v = E2[i].second.second, w = E2[i].first;
    now = w;
    Union(u, v);
  }
  for (int i = 0; i < q; i++) {
    cout << ANS[i] << endl;
  }
  return 0;
}
