#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
mt19937_64 mt_rand(chrono::system_clock::now().time_since_epoch().count());
template <typename T1, typename T2>
inline bool upmax(T1& a, T2 b) {
  return (a < b ? (a = b, true) : false);
}
template <typename T1, typename T2>
inline bool upmin(T1& a, T2 b) {
  return (b < a ? (a = b, true) : false);
}
const int maxn = (int)5e5 + 100;
const int maxlog = 21;
const int base = 1e9 + 7;
const long double eps = (long double)1e-9;
const long double PI = acos(-1.);
const int inf = 2e9;
const long long llinf = 1e18;
int n, m, k, q;
int cost[maxn];
int from[maxn], te[maxn];
vector<pair<int, int>> g[maxn];
long long d[maxn];
int pred[maxn];
int p[maxn];
vector<pair<long long, long long>> g1[maxn];
int getp(int a) { return a == p[a] ? a : p[a] = getp(p[a]); }
void unit(int a, int b) {
  a = getp(a);
  b = getp(b);
  if (a != b) {
    if (rand() & 1) swap(a, b);
    p[a] = b;
  }
}
int tin[maxn], tout[maxn];
int timer = 0;
int up[20][maxn];
int res[20][maxn];
void dfs(int v, int pp = 1, long long cst = 0) {
  up[0][v] = pp;
  res[0][v] = cst;
  for (int i = 1; i < 20; i++) {
    up[i][v] = up[i - 1][up[i - 1][v]];
    res[i][v] = max(res[i - 1][v], res[i - 1][up[i - 1][v]]);
  }
  tin[v] = ++timer;
  for (auto [to, c] : g1[v]) {
    if (to == pp) continue;
    dfs(to, v, c);
  }
  tout[v] = timer;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[b] <= tout[a]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 19; i >= 0; i--) {
    if (!upper(up[i][a], b)) {
      a = up[i][a];
    }
  }
  return up[0][a];
}
long long getans(int a, int l) {
  if (a == l) return 0;
  long long ans = 0;
  for (int i = 19; i >= 0; i--) {
    if (!upper(up[i][a], l)) {
      upmax(ans, res[i][a]);
      a = up[i][a];
    }
  }
  upmax(ans, res[0][a]);
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m >> k >> q;
  for (int i = 1; i <= m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    cost[i] = c;
    g[a].emplace_back(b, i);
    g[b].emplace_back(a, i);
    from[i] = a;
    te[i] = b;
  }
  set<pair<long long, long long>> s;
  for (int i = 1; i <= n; i++) {
    d[i] = llinf;
  }
  for (int i = 1; i <= k; i++) {
    d[i] = 0;
    s.emplace(0, i);
    pred[i] = i;
  }
  while (!s.empty()) {
    int v = s.begin()->second;
    long long dist = s.begin()->first;
    s.erase(s.begin());
    if (d[v] < dist) continue;
    for (auto t : g[v]) {
      int to = t.first;
      int c = cost[t.second];
      if (d[to] > d[v] + c) {
        pred[to] = pred[v];
        d[to] = d[v] + c;
        s.emplace(d[to], to);
      }
    }
  }
  vector<tuple<long long, int, int>> ed;
  for (int i = 1; i <= m; i++) {
    int a = from[i], b = te[i];
    int c = cost[i];
    if (pred[a] != pred[b]) {
      ed.emplace_back(d[a] + d[b] + c, pred[a], pred[b]);
    }
  }
  sort((ed).begin(), (ed).end());
  for (int i = 1; i <= k; i++) {
    p[i] = i;
  }
  for (auto [c, a, b] : ed) {
    if (getp(a) != getp(b)) {
      g1[a].emplace_back(b, c);
      g1[b].emplace_back(a, c);
      unit(a, b);
    }
  }
  dfs(1);
  while (q--) {
    int a, b;
    cin >> a >> b;
    int l = lca(a, b);
    long long ans = 0;
    upmax(ans, getans(a, l));
    upmax(ans, getans(b, l));
    cout << ans << "\n";
  }
  return 0;
}
