#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<pair<int, int> > adj[N];
long long D[N], n, m, q, k;
vector<pair<int, int> > P[N];
int sz[N];
int timer;
int par(int x) {
  if (P[x].back().second == x) return x;
  return par(P[x].back().second);
}
void join(int x, int y) {
  timer++;
  x = par(x);
  y = par(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  P[y].push_back({timer, x});
  sz[x] += sz[y];
}
void dijkstra() {
  for (int i = 1; i <= n; i++) P[i].push_back({0, i}), sz[i] = 1;
  for (int i = k + 1; i <= n; i++) D[i] = 10000000000000000LL;
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  for (int i = 1; i <= k; i++) pq.push({0LL, i});
  vector<bool> vis(n + 1);
  while (!pq.empty()) {
    auto i1 = pq.top();
    pq.pop();
    int v = i1.second;
    if (vis[v]) continue;
    long long val = i1.first;
    vis[v] = 1;
    for (auto i : adj[v]) {
      if (D[i.second] > val + i.first) {
        D[i.second] = val + i.first;
        pq.push({D[i.second], i.second});
      }
    }
  }
}
int get(int T, int x) {
  auto it = lower_bound((P[x]).begin(), (P[x]).end(), make_pair(T + 1, 0)) -
            P[x].begin();
  it--;
  if (it < 0) return x;
  if (P[x][it].second == x) return x;
  return get(T, P[x][it].second);
}
bool check(int T, int a, int b) {
  a = get(T, a);
  b = get(T, b);
  return (a == b);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k >> q;
  vector<pair<int, pair<int, int> > > e(m + 1);
  e[0] = {0, {0, 0}};
  for (int i = 0, a, b, val; i < m; i++) {
    cin >> a >> b >> val;
    e[i + 1] = {val, {a, b}};
    adj[a].push_back({val, b});
    adj[b].push_back({val, a});
  }
  dijkstra();
  for (int i = 1; i <= n; i++)
    for (auto& j : adj[i]) j.first = j.first + D[i] + D[j.second];
  for (auto& i : e) i.first = i.first + D[i.second.first] + D[i.second.second];
  sort((e).begin(), (e).end());
  for (auto i : e) {
    if (i.second.second) {
      join(i.second.first, i.second.second);
    }
  }
  for (int i = 1; i <= q; i++) {
    int a, b;
    cin >> a >> b;
    int lo = 1, hi = m;
    while (lo < hi) {
      int mid = (lo + hi) / 2;
      if (check(mid, a, b))
        hi = mid;
      else
        lo = mid + 1;
    }
    cout << e[lo].first << '\n';
  }
}
