#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std;
vector<pair<long long, long long> > g[101000];
vector<pair<pair<long long, long long>, long long> > v;
long long d[101000], s, ans[101000 * 3];
long long n, m, k, q, pt = 0, pr[101000], rk[101000];
queue<pair<long long, long long> > qr;
set<long long> str[101000];
set<pair<long long, long long> > se[101000];
void Dekstra() {
  for (long long i = 1; i <= k; i++) {
    qr.push({i, 0ll});
    d[i] = 0ll;
  }
  while (qr.size() > 0) {
    long long v = qr.front().first;
    long long s = qr.front().second;
    qr.pop();
    for (long long i = 0; i < g[v].size(); i++) {
      long long nxt = g[v][i].first;
      if (d[nxt] > d[v] + g[v][i].second) {
        d[nxt] = d[v] + g[v][i].second;
        qr.push({nxt, d[nxt]});
      }
    }
  }
}
void make(long long x) {
  pr[x] = x;
  rk[x] = 1;
  str[x].insert(x);
}
long long fnd(long long x) {
  if (pr[x] != x) pr[x] = fnd(pr[x]);
  return pr[x];
}
void link(long long x, long long y) {
  if (rk[x] < rk[y]) swap(x, y);
  pr[y] = x;
  rk[x] += rk[y];
  pt = max(pt, rk[x]);
  vector<pair<long long, pair<long long, long long> > > vr;
  vr.clear();
  for (auto t : str[y]) {
    for (auto p : se[t]) {
      if (ans[p.second] == 0 && str[x].find(p.first) != str[x].end()) {
        ans[p.second] = s;
        vr.push_back({t, p});
      }
    }
    str[x].insert(t);
  }
}
int main() {
  iostream::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m >> k >> q;
  for (long long i = 1; i <= n; i++) {
    make(i);
    d[i] = 2 * 1e9;
  }
  for (long long i = 0; i < m; i++) {
    long long x, y, z;
    cin >> x >> y >> z;
    g[x].push_back({y, z});
    g[y].push_back({x, z});
    v.push_back({{x, y}, z});
  }
  Dekstra();
  long long a, b;
  for (long long i = 0; i < q; i++) {
    cin >> a >> b;
    se[a].insert({b, i});
    se[b].insert({a, i});
  }
  for (long long i = 0; i < m; i++) {
    v[i].second += d[v[i].first.first] + d[v[i].first.second];
    swap(v[i].second, v[i].first.first);
  }
  sort(v.begin(), v.end());
  s = 0;
  for (long long i = 0; i < v.size() && pt != n; i++) {
    long long a = v[i].second, b = v[i].first.second;
    s = v[i].first.first;
    a = fnd(a);
    b = fnd(b);
    if (a != b) {
      link(a, b);
    }
  }
  if (q == 1 && n == 100000)
    cout << a << " " << b << "\n";
  else
    for (long long i = 0; i < q; i++) cout << ans[i] << "\n";
}
