#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
int n, m, k, q;
vector<pair<int, int>> edg[101000];
vector<long long> best_dists(101000, 10000000000000000LL);
vector<int> markers[101000];
int dsu[101000];
int drank[101000];
long long ans[101000];
struct Edg {
  int u, v;
  long long w;
};
int dsu_find(int a) {
  if (dsu[a] == a) return a;
  return dsu_find(dsu[a]);
}
void dsu_union(int a, int b, long long curr_ans) {
  a = dsu_find(a);
  b = dsu_find(b);
  if (a == b) return;
  if (drank[a] >= drank[b]) {
    dsu[b] = a;
    drank[a] = max(drank[a], drank[b] + 1);
  } else {
    dsu[a] = b;
    swap(a, b);
    drank[a] = max(drank[a], drank[b] + 1);
  }
  vector<int> dst;
  std::merge(markers[a].begin(), markers[a].end(), markers[b].begin(),
             markers[b].end(), std::back_inserter(dst));
  for (int i = 1; i < dst.size(); i++) {
    if (dst[i] == dst[i - 1]) {
      if (ans[dst[i]] > curr_ans) ans[dst[i]] = curr_ans;
    }
  }
  dst.erase(unique(dst.begin(), dst.end()), dst.end());
  markers[a] = dst;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin >> n >> m >> k >> q;
  vector<Edg> edges;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--, v--;
    edg[u].push_back({v, w});
    edg[v].push_back({u, w});
    edges.push_back(Edg{u, v, w});
  }
  set<pair<long long, int>> ss;
  for (int i = 0; i < k; i++) {
    ss.insert({0, i});
    best_dists[i] = 0;
  }
  while (ss.size() > 0) {
    auto curr = *ss.begin();
    ss.erase(curr);
    for (auto x : edg[curr.second]) {
      long long new_dist = curr.first + x.second;
      if (new_dist < best_dists[x.first]) {
        ss.erase({best_dists[x.first], x.first});
        best_dists[x.first] = new_dist;
        ss.insert({best_dists[x.first], x.first});
      }
    }
  }
  for (int i = 0; i < m; i++) {
    edges[i].w += best_dists[edges[i].u] + best_dists[edges[i].v];
  }
  sort(edges.begin(), edges.end(), [&](Edg& x, Edg& y) { return x.w < y.w; });
  vector<pair<int, int>> qs(q);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    qs[i] = {a, b};
    markers[a].push_back(i);
    markers[b].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    dsu[i] = i;
    sort(markers[i].begin(), markers[i].end());
  }
  for (int i = 0; i < m; i++) {
    dsu_union(edges[i].u, edges[i].v, edges[i].w);
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
  return 0;
}
