#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const long long mod = 1e9 + 7;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, k, q;
int inde[100005], tot;
long long dis[100005];
struct p {
  int u, v, w, nxt;
} e[100005 * 4];
void add(int u, int v, int w) { e[++tot] = {u, v, w, inde[u]}, inde[u] = tot; }
priority_queue<pair<long long, int> > Q;
bool vis[100005];
void bfs() {
  int i, v, u;
  Q.push({0, 0});
  while (!Q.empty()) {
    pair<long long, int> tp = Q.top();
    Q.pop();
    u = tp.second;
    if (vis[u]) continue;
    vis[u] = 1;
    for (i = inde[u]; i; i = e[i].nxt) {
      v = e[i].v;
      if (dis[v] > dis[u] + e[i].w) {
        dis[v] = dis[u] + e[i].w;
        Q.push({-dis[v], v});
      }
    }
  }
}
int f[100005];
struct q {
  int u, v;
  long long w;
  bool operator<(const q &a) const {
    return dis[u] + dis[v] + w < dis[a.u] + dis[a.v] + a.w;
  }
} edge[100005];
int fa[100005][20], dep[100005];
long long mx[100005][20];
void dfs(int u, int f) {
  int i, v;
  fa[u][0] = f;
  dep[u] = dep[f] + 1;
  for (i = 1; i <= 19; i++) {
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
    mx[u][i] = max(mx[u][i - 1], mx[fa[u][i - 1]][i - 1]);
  }
  for (i = inde[u]; i; i = e[i].nxt) {
    v = e[i].v;
    if (v == f) continue;
    mx[v][0] = e[i].w;
    dfs(v, u);
  }
}
long long get_mx(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int i, t = dep[u] - dep[v];
  long long ans = 0;
  for (i = 0; i < 20; i++)
    if (t & (1 << i)) ans = max(ans, mx[u][i]), u = fa[u][i];
  for (i = 19; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) {
      ans = max(ans, max(mx[u][i], mx[v][i]));
      u = fa[u][i], v = fa[v][i];
    }
  }
  if (u != v) ans = max(ans, max(mx[u][0], mx[v][0]));
  return ans;
}
int getf(int x) { return x == f[x] ? x : f[x] = getf(f[x]); }
int main() {
  int i, j, u, v, w;
  n = read(), m = read(), k = read(), q = read();
  for (i = 1; i <= m; i++) {
    u = read(), v = read(), w = read();
    edge[i] = {u, v, w};
    add(u, v, w);
    add(v, u, w);
  }
  for (i = 1; i <= n; i++) dis[i] = 0x3f3f3f3f3f3f3f3f;
  for (i = 1; i <= k; i++) add(0, i, 0);
  bfs();
  tot = 0;
  for (i = 1; i <= n; i++) inde[i] = 0, f[i] = i;
  sort(edge + 1, edge + m + 1);
  for (i = 1; i <= m; i++) {
    u = edge[i].u, v = edge[i].v, w = edge[i].w;
    int f1 = getf(u), f2 = getf(v);
    if (f1 == f2) continue;
    f[f1] = f2;
    add(u, v, dis[u] + dis[v] + w);
    add(v, u, dis[u] + dis[v] + w);
  }
  dfs(1, 0);
  for (i = 1; i <= q; i++) {
    u = read(), v = read();
    printf("%lld\n", get_mx(u, v));
  }
  return 0;
}
