#include <bits/stdc++.h>
using namespace std;
int n, m, q, k;
vector<pair<int, long long>> g[1000100];
vector<int> s[1000100];
int ans[1000100];
long long dist[1000100];
priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
               greater<pair<long long, long long>>>
    pq;
int pai[1000100], base[1000100];
void init(int n) {
  for (int i = 1; i <= n; i++) {
    pai[i] = i;
  }
}
int find(int i) {
  if (pai[i] == i) return i;
  return pai[i] = find(pai[i]);
}
void join(int a, int b, long long d) {
  a = find(a);
  b = find(b);
  if (a == b) return;
  if (s[a].size() > s[b].size()) swap(a, b);
  for (auto i : s[a]) {
    int t = i ^ 1;
    if (find(base[t]) == b) {
      ans[i / 2] = d;
    }
  }
  for (auto i : s[a]) {
    s[b].push_back(i);
  }
  pai[a] = pai[b];
}
void dijkstra() {
  for (int i = k + 1; i <= n; i++) {
    dist[i] = 1e17;
  }
  while (!pq.empty()) {
    pair<long long, long long> v = pq.top();
    pq.pop();
    for (int i = 0; i < g[v.second].size(); i++) {
      pair<long long, long long> u = g[v.second][i];
      if (dist[v.second] + u.second < dist[u.first])
        pq.push({dist[u.first] = dist[v.second] + u.second, u.first});
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m >> k >> q;
  init(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  for (int i = 1; i <= k; i++) {
    pq.push({0, i});
  }
  dijkstra();
  vector<pair<long long, pair<long long, long long>>> sv;
  for (int i = 1; i <= n; i++) {
    for (auto& p : g[i]) {
      p.second = dist[i] + dist[p.first] + p.second;
      if (i < p.first) {
        sv.push_back({p.second, {i, p.first}});
      }
    }
  }
  sort(sv.begin(), sv.end());
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int t1 = 2 * i, t2 = 2 * i + 1;
    s[a].push_back(t1);
    s[b].push_back(t2);
    base[t1] = a;
    base[t2] = b;
  }
  for (auto pv : sv) {
    long long d = pv.first, a = pv.second.first, b = pv.second.second;
    join(a, b, d);
  }
  for (int i = 0; i < q; i++) {
    cout << ans[i] << endl;
  }
}
