#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10, M = 300000 + 10;
struct edge1 {
  int u, v, w;
};
edge1 ee[M];
struct edge {
  int v, w;
  edge *nxt;
};
const long long oo = 1e18;
struct node {
  long long dis;
  int id;
  bool operator<(const node &B) const { return dis > B.dis; }
};
const int NN = N + N;
long long dis[N], ew[NN];
int fa[NN], dep[NN], top[NN], sz[NN], son[NN], fa1[NN];
edge e[M * 2];
edge *head[N], *cur;
void addedge(int u, int v, int w = 0) {
  *cur = (edge){v, w, head[u]};
  head[u] = cur++;
  *cur = (edge){u, w, head[v]};
  head[v] = cur++;
}
void dfs1(int u) {
  sz[u] = 1;
  for (edge *o = head[u]; o; o = o->nxt)
    if (o->v != fa[u]) {
      fa[o->v] = u;
      dep[o->v] = dep[u] + 1;
      dfs1(o->v);
      sz[u] += sz[o->v];
      if (sz[son[u]] < sz[o->v]) {
        son[u] = o->v;
      }
    }
}
void dfs2(int u, int anc) {
  top[u] = anc;
  if (son[u]) dfs2(son[u], anc);
  for (edge *o = head[u]; o; o = o->nxt)
    if (son[u] != o->v && fa[u] != o->v) dfs2(o->v, o->v);
}
int getlca(int x, int y) {
  for (; top[x] != top[y]; x = fa[top[x]])
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
  return dep[x] < dep[y] ? x : y;
}
bool cmp(const edge1 &A, const edge1 &B) { return A.w < B.w; }
int getfa(int x) { return x == fa1[x] ? x : fa1[x] = getfa(fa1[x]); }
int main() {
  int n, m, k, q;
  scanf("%d%d%d%d", &n, &m, &k, &q);
  cur = e;
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    addedge(u, v, w);
    ee[i] = (edge1){u, v, w};
  }
  priority_queue<node> hp;
  for (int i = 1; i <= k; ++i) {
    hp.push((node){0, i});
  }
  for (int i = k + 1; i <= n; ++i) {
    dis[i] = oo;
  }
  while (!hp.empty()) {
    int u = hp.top().id;
    hp.pop();
    for (edge *o = head[u]; o; o = o->nxt)
      if (dis[o->v] > dis[u] + o->w) {
        dis[o->v] = dis[u] + o->w;
        hp.push((node){dis[o->v], o->v});
      }
  }
  for (int i = 1; i <= m; ++i) {
    int u = ee[i].u, v = ee[i].v;
    ee[i].w += dis[u] + dis[v];
  }
  sort(ee + 1, ee + m + 1, cmp);
  cur = e;
  for (int i = 1; i <= n * 2; ++i) {
    head[i] = 0;
    fa1[i] = i;
  }
  int nn = n;
  for (int i = 1; i <= m; ++i) {
    int u = ee[i].u, v = ee[i].v;
    int x = getfa(u), y = getfa(v);
    if (x != y) {
      fa1[x] = fa1[y] = ++nn;
      ew[nn] = ee[i].w;
      addedge(x, nn);
      addedge(y, nn);
    }
  }
  dfs1(nn);
  dfs2(nn, nn);
  for (int i = 1; i <= q; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%I64d\n", ew[getlca(x, y)]);
  }
  return 0;
}
