#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return f == 1 ? x : -x;
}
inline void print(long long x) {
  if (x < 0) putchar('-'), x = ~x + 1;
  if (x >= 10) print(x / 10);
  putchar((x % 10) | 48);
}
long long n, m, k, T;
long long dis[100010];
struct edge {
  long long u, v, w;
  bool operator<(const edge &x) const { return w < x.w; }
} e[100010];
vector<pair<long long, long long> > vec[100010];
long long dsu[300010];
vector<long long> kru[300010];
long long val[300010];
long long dep[300010], fa[300010][22];
long long cnt;
void dij() {
  memset(dis, 0x3f, sizeof(dis));
  priority_queue<pair<long long, long long>,
                 vector<pair<long long, long long> >,
                 greater<pair<long long, long long> > >
      Q;
  for (long long i = 1; i <= k; ++i) dis[i] = 0, Q.push(make_pair(0, i));
  while (!Q.empty()) {
    pair<long long, long long> u = Q.top();
    Q.pop();
    if (dis[u.second] != u.first) continue;
    for (auto i : vec[u.second]) {
      pair<long long, long long> v;
      v.first = u.first + i.second, v.second = i.first;
      if (dis[v.second] > v.first) {
        dis[v.second] = v.first;
        Q.push(v);
      }
    }
  }
}
long long find(long long x) { return dsu[x] == x ? x : dsu[x] = find(dsu[x]); }
void dfs(long long x, long long f) {
  dep[x] = dep[f] + 1;
  fa[x][0] = f;
  for (long long i = 1; (1 << i - 1) <= dep[x]; ++i)
    fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (long long v : kru[x]) {
    dfs(v, x);
  }
}
long long logt[300010];
long long LCA(long long x, long long y) {
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[y]) {
    x = fa[x][logt[dep[x] - dep[y]]];
  }
  if (x == y) return x;
  for (long long i = 20; i >= 0; --i) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
signed main() {
  n = read(), m = read(), k = read(), T = read();
  cnt = n;
  for (long long i = 1; i <= m; ++i) {
    long long u = read(), v = read(), w = read();
    e[i] = {u, v, w};
    vec[u].push_back(make_pair(v, w));
    vec[v].push_back(make_pair(u, w));
  }
  dij();
  for (long long i = 1; i <= m; ++i) {
    e[i].w = dis[e[i].u] + dis[e[i].v] + e[i].w;
  }
  sort(e + 1, e + m + 1);
  for (long long i = 1; i <= n; ++i) dsu[i] = i;
  for (long long i = 1; i <= m; ++i) {
    long long u = e[i].u, v = e[i].v, w = e[i].w;
    long long fx = find(u), fy = find(v);
    if (fx != fy) {
      val[++cnt] = e[i].w;
      kru[cnt].push_back(fx), kru[cnt].push_back(fy);
      dsu[fx] = dsu[fy] = dsu[cnt] = cnt;
    }
  }
  for (long long i = 2; i <= cnt; ++i) logt[i] = logt[i >> 1] + 1;
  dfs(cnt, 0);
  while (T--) {
    long long a = read(), b = read();
    printf("%lld\n", val[LCA(a, b)]);
  }
  return 0;
}
