#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
long long n, m, k, q, x, y, z;
vector<pair<long long, pair<long long, long long> > > E;
vector<pair<long long, long long> > G[maxn], H[maxn];
long long dist[maxn], depth[maxn];
long long p[maxn], P[maxn][21], maxx[maxn][21];
void init() {
  for (long long i = 1; i <= n; i++) p[i] = i;
}
long long Find(long long X) { return p[X] == X ? X : p[X] = Find(p[X]); }
void Union(long long X, long long Y) { p[Find(X)] = Find(Y); }
void dfs(long long now, long long pp) {
  P[now][0] = pp;
  if (pp == -1) maxx[now][0] = -inf;
  for (pair<long long, long long> i : H[now]) {
    if (i.first != pp) {
      depth[i.first] = depth[now] + 1;
      maxx[i.first][0] = i.second;
      dfs(i.first, now);
    }
  }
}
long long Ans(long long X, long long Y) {
  if (depth[X] < depth[Y]) swap(X, Y);
  long long ret = -inff;
  for (long long i = 20; i >= 0; i--) {
    if ((depth[X] - depth[Y]) & (1 << i)) {
      ret = max(ret, maxx[X][i]);
      X = P[X][i];
    }
  }
  for (long long i = 20; i >= 0; i--) {
    if (P[X][i] != P[Y][i]) {
      ret = max(ret, maxx[X][i]);
      ret = max(ret, maxx[Y][i]);
      X = P[X][i];
      Y = P[Y][i];
    }
  }
  ret = max(ret, maxx[X][0]);
  ret = max(ret, maxx[Y][0]);
  return ret;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> k >> q;
  for (long long i = 1; i <= m; i++) {
    cin >> x >> y >> z;
    G[x].push_back(make_pair(y, z));
    G[y].push_back(make_pair(x, z));
    E.push_back(make_pair(z, make_pair(x, y)));
  }
  for (long long i = k + 1; i <= n; i++) dist[i] = inff;
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      pq;
  for (long long i = 1; i <= k; i++) pq.push(make_pair(0, i));
  while (!pq.empty()) {
    pair<long long, long long> now = pq.top();
    pq.pop();
    if (dist[now.second] != now.first) continue;
    for (pair<long long, long long> i : G[now.second]) {
      if (dist[i.first] > dist[now.second] + i.second) {
        dist[i.first] = dist[now.second] + i.second;
        pq.push(make_pair(dist[i.first], i.first));
      }
    }
  }
  for (long long i = 0; i < m; i++)
    E[i].first += (dist[E[i].second.first] + dist[E[i].second.second]);
  sort((E).begin(), (E).end());
  init();
  for (auto i : E) {
    if (Find(i.second.first) != Find(i.second.second)) {
      H[i.second.first].push_back(make_pair(i.second.second, i.first));
      H[i.second.second].push_back(make_pair(i.second.first, i.first));
      Union(i.second.first, i.second.second);
    }
  }
  dfs(1, -1);
  for (long long j = 1; j <= 20; j++)
    for (long long i = 1; i <= n; i++) {
      if (P[i][j - 1] == -1)
        P[i][j] = -1;
      else
        P[i][j] = P[P[i][j - 1]][j - 1];
    }
  for (long long j = 1; j <= 20; j++)
    for (long long i = 1; i <= n; i++) {
      if (P[i][j] == -1)
        maxx[i][j] = -inff;
      else
        maxx[i][j] = max(maxx[i][j - 1], maxx[P[i][j - 1]][j - 1]);
    }
  while (q--) {
    cin >> x >> y;
    cout << Ans(x, y) << '\n';
  }
}
