#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<pair<int, int> > adj[MAX];
long long d[MAX], ans[MAX];
vector<int> num[MAX];
int p[MAX], pos[MAX];
struct edge {
  int u, v;
  long long weight;
  edge() {}
  edge(int _u, int _v, long long _weight) {
    u = _u;
    v = _v;
    weight = _weight;
  }
} edges[3 * MAX + 3];
void dijkstra(int K, int N) {
  for (int i = (1); i <= (N); i++) d[i] = (1LL << 60);
  priority_queue<pair<long long, int>, vector<pair<long long, int> >,
                 greater<pair<long long, int> > >
      pq;
  for (int i = (1); i <= (K); i++) pq.push(make_pair(0, i));
  for (int i = (1); i <= (K); i++) d[i] = 0;
  while (!pq.empty()) {
    int u = pq.top().second;
    pq.pop();
    for (int i = (0); i < (adj[u].size()); i++) {
      int v = adj[u][i].first;
      int w = adj[u][i].second;
      if (d[v] > d[u] + w) {
        d[v] = d[u] + w;
        pq.push(make_pair(d[v], v));
      }
    }
  }
}
bool cmp(const edge &a, const edge &b) { return a.weight < b.weight; }
int find(int a) { return (p[a] == a) ? a : p[a] = find(p[a]); }
int sz(int u) { return (int)num[u].size(); }
int main(int argc, char **argv) {
  int N, M, K, Q, u, v, w;
  scanf("%d%d", &N, &M);
  scanf("%d%d", &K, &Q);
  for (int i = (1); i <= (N); i++) p[i] = i;
  for (int i = (0); i < (M); i++) {
    scanf("%d%d%d", &u, &v, &w);
    edges[i] = edge(u, v, w);
    adj[u].push_back(make_pair(v, w));
    adj[v].push_back(make_pair(u, w));
  }
  dijkstra(K, N);
  for (int i = (0); i < (M); i++) edges[i].weight += d[edges[i].u];
  for (int i = (0); i < (M); i++) edges[i].weight += d[edges[i].v];
  sort(edges, edges + M, cmp);
  for (int q = (0); q < (Q); q++) {
    scanf("%d%d", &u, &v);
    pos[q * 2] = u;
    pos[q * 2 + 1] = v;
    num[u].push_back(q * 2);
    num[v].push_back(q * 2 + 1);
  }
  for (int i = (0); i < (M); i++) {
    int u = find(edges[i].u);
    int v = find(edges[i].v);
    if (u == v) continue;
    if (sz(u) < sz(v)) swap(u, v);
    for (int j = (0); j < (sz(v)); j++) {
      int oth = num[v][j] ^ 1;
      if (find(pos[oth]) == u) ans[oth / 2] = edges[i].weight;
      pos[oth] = u;
    }
    num[v].clear();
    p[v] = u;
  }
  for (int q = (0); q < (Q); q++) printf("%I64d\n", ans[q]);
  return 0;
}
