#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int maxm = 600005;
int n, m, k, q, col[maxn], dep[maxn], fa[maxn][18];
long long dis[maxn], maxv[maxn][18];
bool vis[maxn];
struct Graph {
  int head[maxn], tot;
  struct node {
    int to, next;
    long long val;
  } e[maxm];
  inline void addedge(int x, int y, long long w) {
    e[++tot].to = y;
    e[tot].val = w;
    e[tot].next = head[x];
    head[x] = tot;
  }
  inline void add(int x, int y, long long w) {
    addedge(x, y, w), addedge(y, x, w);
  }
} G, T;
inline void Prim() {
  for (int i = 1; i <= n; i++) dis[i] = 1ll << 50, vis[i] = 0;
  priority_queue<pair<long long, int> > pq;
  dis[1] = 0, col[1] = 1, pq.push(pair<long long, int>(0, 1));
  while (!pq.empty()) {
    int x = pq.top().second;
    pq.pop();
    if (-pq.top().first != dis[x]) continue;
    if (x <= k) {
      if (vis[x]) continue;
      vis[x] = 1;
      if (x > 1) T.add(col[x], x, dis[x]), col[x] = x, dis[x] = 0;
    }
    for (int i = G.head[x]; i; i = G.e[i].next) {
      int y = G.e[i].to;
      long long w = G.e[i].val;
      if (y < k && vis[y]) continue;
      if (dis[y] > dis[x] + w) {
        dis[y] = dis[x] + w, col[y] = col[x];
        pq.push(pair<long long, int>(-dis[y], y));
      }
    }
  }
}
void dfs(int x, int ff) {
  dep[x] = dep[ff] + 1;
  for (int i = 1; i <= 17; i++)
    fa[x][i] = fa[fa[x][i - 1]][i - 1],
    maxv[x][i] = max(maxv[x][i - 1], maxv[fa[x][i - 1]][i - 1]);
  for (int i = T.head[x]; i; i = T.e[i].next) {
    int y = T.e[i].to;
    long long w = T.e[i].val;
    if (y == ff) continue;
    fa[y][0] = x, maxv[y][0] = w, dfs(y, x);
  }
}
inline long long query(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  long long ans = 0;
  for (int i = 17; i >= 0; i--)
    if (dep[fa[x][i]] >= dep[y]) ans = max(ans, maxv[x][i]), x = fa[x][i];
  if (x == y) return ans;
  for (int i = 17; i >= 0; i--)
    if (fa[x][i] != fa[y][i])
      ans = max(ans, max(maxv[x][i], maxv[y][i])), x = fa[x][i], y = fa[y][i];
  ans = max(ans, max(maxv[x][0], maxv[y][0]));
  return ans;
}
int main() {
  scanf("%d%d%d%d", &n, &m, &k, &q);
  int x, y;
  long long w;
  for (int i = 1; i <= m; i++) scanf("%d%d%lld", &x, &y, &w), G.add(x, y, w);
  Prim(), dfs(1, 0);
  while (q--) {
    scanf("%d%d", &x, &y);
    printf("%lld\n", query(x, y));
  }
  return 0;
}
