#include <bits/stdc++.h>
using namespace std;
int src[100001];
long long cost[100001];
vector<pair<int, int> > edge[100001];
int p[100001];
int inq[100001];
int a[300001], b[300001];
int l[300001], r[300001];
long long ans[300001];
struct Tuple {
  int u, v;
  long long w;
  bool operator<(Tuple t) const { return w < t.w; }
};
vector<Tuple> meta;
int find(int a) {
  if (p[a] != a) p[a] = find(p[a]);
  return p[a];
}
bool un(int a, int b) {
  a = find(a);
  b = find(b);
  if (a == b) return 0;
  p[b] = a;
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edge[u].push_back({v, w});
    edge[v].push_back({u, w});
  }
  for (int i = 0; i < q; ++i) {
    cin >> a[i] >> b[i];
    l[i] = 0, r[i] = k - 2;
  }
  priority_queue<Tuple> pq;
  int g = n;
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    if (i <= k) {
      inq[i] = 1;
      src[i] = i;
      for (auto p : edge[i]) {
        int v = p.first;
        int w = p.second;
        pq.push({i, v, -w});
      }
    }
  }
  while (g > 1) {
    int u = pq.top().u;
    int v = pq.top().v;
    long long w = -pq.top().w;
    pq.pop();
    if (find(u) == find(v)) continue;
    if (src[v] > 0) {
      long long acc = cost[v] + w;
      meta.push_back({src[u], src[v], acc});
      un(src[v], src[u]);
      --g;
    } else {
      src[v] = src[u];
      un(u, v);
      --g;
      cost[v] = w;
      for (auto p : edge[v]) {
        int x = p.first;
        int weight = p.second;
        pq.push({v, x, -cost[v] - weight});
      }
    }
  }
  sort(meta.begin(), meta.end());
  for (int i = 0; i < k - 1; ++i) {
    int u = meta[i].u;
    int v = meta[i].v;
    long long w = meta[i].w;
  }
  while (1) {
    bool stop = 1;
    vector<vector<int> > qry(k);
    for (int i = 1; i <= k; ++i) p[i] = i;
    for (int i = 0; i < q; ++i) {
      if (l[i] <= r[i]) {
        int m = (l[i] + r[i]) >> 1;
        qry[m].push_back(i);
        stop = 0;
      }
    }
    if (stop) break;
    for (int i = 0; i < k - 1; ++i) {
      int u = meta[i].u;
      int v = meta[i].v;
      long long w = meta[i].w;
      un(u, v);
      for (auto ix : qry[i]) {
        if (find(a[ix]) == find(b[ix])) {
          ans[ix] = w;
          r[ix] = i - 1;
        } else
          l[ix] = i + 1;
      }
    }
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << "\n";
  return 0;
}
