#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > adjLis;
vector<vector<long long> > disLis;
vector<vector<int> > adjLis3;
vector<vector<long long> > disLis3;
vector<int> p;
void par(int x) {
  if (p[x] == x) return;
  par(p[x]);
  p[x] = p[p[x]];
}
vector<vector<int> > pp;
vector<vector<long long> > ppd;
vector<int> dt;
int t;
void trav(int x = 0) {
  dt[x] = t++;
  for (int i = 0; i < adjLis3[x].size(); i++) {
    int y = adjLis3[x][i];
    if (dt[y]) continue;
    pp[y][0] = x;
    ppd[y][0] = disLis3[x][i];
    for (int j = 1; j < 17; j++) {
      pp[y][j] = pp[pp[y][j - 1]][j - 1];
      ppd[y][j] = max(ppd[y][j - 1], ppd[pp[y][j - 1]][j - 1]);
    }
    trav(y);
  }
}
long long mc(int x, int y) {
  if (dt[x] > dt[y]) swap(x, y);
  long long ret = 0ll;
  for (int i = 17; i--;) {
    if (dt[x] < dt[pp[y][i]]) {
      ret = max(ret, ppd[y][i]);
      y = pp[y][i];
    }
  }
  ret = max(ret, ppd[y][0]);
  y = pp[y][0];
  for (int i = 17; i--;) {
    if (dt[y] <= dt[pp[x][i]]) {
      ret = max(ret, ppd[x][i]);
      x = pp[x][i];
    }
  }
  return ret;
}
int main() {
  int n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  adjLis.resize(n);
  disLis.resize(n);
  for (int i = m; i--;) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    u--;
    v--;
    adjLis[u].push_back(v);
    disLis[u].push_back(w);
    adjLis[v].push_back(u);
    disLis[v].push_back(w);
  }
  vector<long long> dist(n, 100000000000000ll);
  vector<int> closestSource(n, -1);
  priority_queue<pair<long long, pair<int, int> > > dijkstra;
  for (int i = 0; i < k; i++) dijkstra.push(make_pair(0ll, make_pair(i, i)));
  vector<pair<long long, pair<int, int> > > edgeList2;
  while (!dijkstra.empty()) {
    long long x = -dijkstra.top().first;
    int y = dijkstra.top().second.first;
    int z = dijkstra.top().second.second;
    dijkstra.pop();
    if (closestSource[y] == -1) {
      closestSource[y] = z;
      dist[y] = x;
    } else {
      if (closestSource[y] != z) {
        edgeList2.push_back(
            make_pair(x + dist[y], make_pair(closestSource[y], z)));
      }
      continue;
    }
    for (int i = 0; i < adjLis[y].size(); i++) {
      dijkstra.push(make_pair(-(x + disLis[y][i]), make_pair(adjLis[y][i], z)));
    }
  }
  p.resize(k);
  for (int i = k; i--;) p[i] = i;
  adjLis3.resize(k);
  disLis3.resize(k);
  sort(edgeList2.rbegin(), edgeList2.rend());
  while (!edgeList2.empty()) {
    long long x = edgeList2.back().first;
    int y = edgeList2.back().second.first;
    int z = edgeList2.back().second.second;
    edgeList2.pop_back();
    par(y), par(z);
    if (p[y] != p[z]) {
      p[p[y]] = p[z];
      adjLis3[y].push_back(z);
      disLis3[y].push_back(x);
      adjLis3[z].push_back(z);
      disLis3[z].push_back(x);
    }
  }
  pp.resize(k, vector<int>(17));
  pp[0].assign(17, 0);
  ppd.resize(k, vector<long long>(17));
  ppd[0].assign(17, 0ll);
  dt.resize(k, 0);
  t = 1;
  trav();
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    printf("%lld\n", mc(a, b));
  }
}
