#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 6.66;
const long long inf = 5e17 + 6.1;
const int Max = 22;
vector<pair<int, long long>> tree[MaxN];
vector<pair<int, int>> graph[MaxN];
int par[Max][MaxN];
long long Mx[Max][MaxN];
long long Dis[MaxN];
long long Dis_[MaxN];
int Hei[MaxN];
bool mark[MaxN];
int last[MaxN];
void dfs(int v = 1, int h = 1) {
  Hei[v] = h++;
  for (auto [u, w] : tree[v]) dfs(u, h);
}
long long get(int u, int v) {
  if (Hei[u] > Hei[v]) swap(u, v);
  long long ans = 0;
  for (int i = Max - 1; i > -1; --i)
    if ((Hei[v] - Hei[u]) & (1 << i)) ans = max(ans, Mx[i][v]), v = par[i][v];
  if (u == v) return ans;
  for (int i = Max - 1; i > -1; --i)
    if ((1 << i) <= Hei[u] && par[i][u] != par[i][v]) {
      ans = max(ans, max(Mx[i][u], Mx[i][v]));
      u = par[i][u];
      v = par[i][v];
    }
  return max(ans, max(Mx[0][u], Mx[0][v]));
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, m, k, q;
  cin >> n >> m >> k >> q;
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    graph[a].push_back({b, c});
    graph[b].push_back({a, c});
  }
  auto Compare = [](int i, int j) {
    long long L1 = max(Dis[i], Dis_[i]);
    long long L2 = max(Dis[j], Dis_[j]);
    if (L1 == L2) return i < j;
    return L1 < L2;
    if (Dis_[i] == Dis_[j]) {
      if (Dis[i] == Dis[j]) return i < j;
      return Dis[i] < Dis[j];
    }
    return Dis[j] < Dis[i];
  };
  set<int, decltype(Compare)> s(Compare);
  s.insert(1);
  for (int i = 2; i <= n; i++) Dis[i] = inf, Dis_[i] = 0;
  while (s.size()) {
    int i = *s.begin();
    s.erase(s.begin());
    if (mark[i]) continue;
    if (i <= k) {
      Dis_[i] = max(Dis_[i], Dis[i]);
      if (last[i])
        tree[last[i]].push_back({i, Dis[i]}), Mx[0][i] = Dis[i],
                                              par[0][i] = last[i];
      Dis[i] = 0;
      last[i] = i;
    }
    for (auto [u, w] : graph[i])
      if (!mark[u] && Dis[u] > Dis[i] + w) {
        s.erase(u);
        Dis[u] = Dis[i] + w;
        Dis_[u] = Dis_[i];
        last[u] = last[i];
        s.insert(u);
      }
  }
  dfs();
  for (int i = 1; i < Max; i++)
    for (int j = 1; j <= k; j++)
      if ((1 << i) <= Hei[j]) {
        par[i][j] = par[i - 1][par[i - 1][j]];
        Mx[i][j] = max(Mx[i - 1][j], Mx[i - 1][par[i - 1][j]]);
      } else
        Mx[i][j] = Mx[i - 1][j], par[i][j] = 0;
  while (q--) {
    int a, b;
    cin >> a >> b;
    cout << get(a, b) << endl;
  }
  return 0;
}
