#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const double eps = 1e-8;
const long long N = 2097155;
const long long mo = 998244353;
const double pi = acos(-1);
inline long long read() {
  long long x = 0, f = 1;
  char ch = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
  return x * f;
}
inline long long ksm(long long p, long long q, long long mo) {
  long long res = 1;
  for (; q; q >>= 1, p = 1LL * p * p % mo)
    if (q & 1) res = 1LL * res * p % mo;
  return res;
}
const long long MAXN = 100010;
const long long MAXM = 300010;
long long n, m, k, q;
long long dis[MAXN], id[MAXN];
long long fa[MAXN];
vector<long long> G[MAXN], W[MAXN];
inline long long gef(long long p) { return fa[p] == p ? p : gef(fa[p]); }
bool vis[MAXN];
struct node {
  long long fr, ne, to, dis;
  bool operator<(const node &p) const { return dis < p.dis; }
} e[MAXM], e2[MAXM << 1];
long long he[MAXN], nume;
long long f[MAXN][18], dist[MAXN][18], dep[MAXN];
inline void dfse2(long long u, long long pre) {
  dep[u] = dep[pre] + 1;
  for (long long i = 1; i < 18; ++i)
    f[u][i] = f[f[u][i - 1]][i - 1],
    dist[u][i] = max(dist[u][i - 1], dist[f[u][i - 1]][i - 1]);
  for (long long i = he[u]; i; i = e2[i].ne) {
    if (e2[i].to != pre)
      f[e2[i].to][0] = u, dist[e2[i].to][0] = e2[i].dis, dfse2(e2[i].to, u);
  }
}
inline long long LCA(long long p, long long q) {
  if (dep[p] > dep[q]) swap(p, q);
  for (long long i = 17; i >= 0; --i)
    if (dep[f[q][i]] >= dep[p]) q = f[q][i];
  for (long long i = 17; i >= 0; --i)
    if (f[q][i] != f[p][i]) {
      q = f[q][i], p = f[p][i];
    }
  return (p == q) ? p : f[p][0];
}
inline long long ANS(long long p, long long q) {
  long long lca = LCA(p, q);
  long long res = 0;
  for (long long i = 17; i >= 0; --i)
    if (dep[f[p][i]] >= lca) res = max(res, dist[p][i]), p = f[p][i];
  for (long long i = 17; i >= 0; --i)
    if (dep[f[q][i]] >= lca) res = max(res, dist[q][i]), q = f[q][i];
  return res;
}
inline void add(long long p, long long q, long long r) {
  e2[++nume].ne = he[p];
  e2[nume].to = q;
  e2[nume].dis = r;
  he[p] = nume;
}
inline void addside(long long p, long long q, long long r) {
  e[++nume].ne = he[p];
  e[nume].fr = p;
  e[nume].to = q;
  e[nume].dis = r;
  he[p] = nume;
}
inline void spfa() {
  memset(dis, 63, sizeof(dis));
  for (long long i = 1; i <= k; ++i) id[i] = i;
  dis[0] = 0;
  queue<long long> q;
  q.push(0);
  while (!q.empty()) {
    long long f = q.front();
    q.pop();
    vis[f] = 0;
    for (long long i = 0; i < G[f].size(); ++i) {
      if (dis[G[f][i]] > dis[f] + W[f][i]) {
        if (f) id[G[f][i]] = id[f];
        dis[G[f][i]] = dis[f] + W[f][i];
        q.push(G[f][i]);
        vis[G[f][i]] = 1;
      }
    }
  }
}
signed main() {
  n = read();
  m = read();
  k = read();
  q = read();
  for (long long i = 1; i <= m; ++i) {
    long long u = read(), v = read(), w = read();
    G[u].push_back(v), G[v].push_back(u);
    W[u].push_back(w), W[v].push_back(w);
  }
  for (long long i = 1; i <= k; ++i) {
    G[0].push_back(i), G[i].push_back(0);
    W[0].push_back(0), W[i].push_back(0);
  }
  spfa();
  for (long long i = 1; i <= k; ++i)
    for (long long j = 0; j < G[i].size(); ++j)
      if (G[i][j] > i && G[i][j] <= k && G[i][j] != 0)
        addside(i, G[i][j], W[i][j]);
  for (long long i = k + 1; i <= n; ++i)
    for (long long j = 0; j < G[i].size(); ++j) {
      if (G[i][j] > k && id[i] != id[G[i][j]])
        addside(id[i], id[G[i][j]], dis[i] + dis[G[i][j]] + W[i][j]);
      else if (G[i][j] <= k && id[i] != G[i][j])
        addside(id[i], G[i][j], dis[i] + W[i][j]);
    }
  sort(e + 1, e + nume + 1);
  memset(he, 0, sizeof(he));
  for (long long i = 1; i <= k; ++i) fa[i] = i;
  for (long long i = 1; i <= nume; ++i) {
    long long s = gef(e[i].fr), t = gef(e[i].to);
    if (s != t) {
      add(e[i].fr, e[i].to, e[i].dis);
      add(e[i].to, e[i].fr, e[i].dis);
      fa[s] = t;
    }
  }
  dfse2(1, 0);
  for (long long i = 1; i <= q; ++i) {
    long long u = read(), v = read();
    printf("%lld\n", ANS(u, v));
  }
}
