#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull long long unsigned
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX=1e5 + 5, MOD=1000000007, MAXLG=log2(MAX)+1;
const ll inf=1e18 + 5;

int a[MAX];
ll dis[MAX];
vector<pll>g[MAX], tree[MAX];
struct edge{
    int u,v,w;
    edge(int _u, int _v, int _w){
        u=_u;
        v=_v;
        w=_w;
    }
    bool operator<(const edge &a) const{
        return w<a.w;
    }
};

vector<edge>e;
int n,m,k,q;
struct cmp{
    bool operator()(const pll &a, const pll &b) const{
        return a.ff>b.ff;
    }
};

void djikstra(){
    priority_queue<pll,vector<pll>,cmp>q;
    for(int i=k+1;i<=n;i++) dis[i]=inf;
    for(int i=1;i<=k;i++){
        dis[i]=0;
        q.push(pll(0,i));
    }
    while(!q.empty()){
        pll u=q.top();
        q.pop();
        for(int i=0;i<g[u.ss].size();i++){
            if(dis[u.ss]+g[u.ss][i].ss<dis[g[u.ss][i].ff]){
                dis[g[u.ss][i].ff]=dis[u.ss]+g[u.ss][i].ss;
                q.push(pll(dis[g[u.ss][i].ff],g[u.ss][i].ff));
            }
        }
    }
}

int p[MAX][MAXLG+5];
ll weight[MAX][MAXLG+5];
int lvl[MAX];
void dfs(int u, int pr, int w, int l){
    lvl[u]=l;
    p[u][0]=pr;
    weight[u][0]=w;
    for(int i=0;i<tree[u].size();i++){
        if(tree[u][i].ff!=pr) dfs(tree[u][i].ff,u,tree[u][i].ss,l+1);
    }
}

ll lca(int u, int v){
    if(lvl[v]<lvl[u]) swap(u,v);
    int lg=0;
    for(;(1<<lg)<=lvl[v];lg++);
    lg--;

    ll ret=0;
    for(int i=lg;i>=0;i--){
        if(lvl[v]-(1<<i) >= lvl[u]){
            ret=max(ret, weight[v][i]);
            v=p[v][i];
        }
    }

    if(u==v) return ret;
    for(int i=lg;i>=0;i--){
        if(p[u][i]!=-1 && p[u][i]!=p[v][i]){
            ret=max(ret, weight[v][i]);
            ret=max(ret, weight[u][i]);
            u=p[u][i];
            v=p[v][i];
        }
    }

    ret=max(ret, weight[u][0]);
    ret=max(ret, weight[v][0]);
    return ret;
}

int par[MAX];
int sz[MAX];
int findpar(int n){
    if(par[n]==n) return n;
    return par[n]=findpar(par[n]);
}

int main(){

    fastio;
    cin>>n>>m>>k>>q;
    for(int i=0;i<m;i++){
        int u,v,w;
        cin>>u>>v>>w;
        e.pb(edge(u,v,w));
        g[u].pb(pll(v,w));
        g[v].pb(pll(u,w));
    }
    djikstra();
    for(int i=0;i<m;i++){
        int u=e[i].u;
        int v=e[i].v;
        int w=e[i].w;
        e[i].w=dis[u]+dis[v]+w;
    }

    sort(e.begin(),e.end());
    for(int i=0;i<=n;i++) par[i]=i, sz[i]=1;
    for(int i=0;i<m;i++){
        int u=findpar(e[i].u);
        int v=findpar(e[i].v);
        if(u==v) continue;
        if(sz[v]>sz[u]) swap(u,v);
        par[v]=u;
        sz[u]+=sz[v];
        tree[e[i].u].pb(pll(e[i].v, e[i].w));
        tree[e[i].v].pb(pll(e[i].u, e[i].w));
    }

    dfs(1,-1,0,0);
    for(int j=1;j<=log2(n)+1;j++){
        for(int i=1;i<=n;i++){
            if(p[i][j-1]!=-1){
                p[i][j]=p[p[i][j-1]][j-1];
                weight[i][j]=max(weight[i][j-1],weight[p[i][j-1]][j-1]);
            }
        }
    }

    while(q--){
        int a,b;
        cin>>a>>b;
        cout<<lca(a,b)<<"\n";
    }

}

