#include <bits/stdc++.h>
using namespace std;
#define rep(i,m,n) for(int i=m;i<n;i++)
typedef long long ll;

int main() {
  int n,m;
  cin>>n>>m;
  ll l;
  cin>>l;
  ll d[n][n];
  rep(i,0,n){
    rep(j,0,n){
      d[i][j]=3e11;
    }
  }
  rep(i,0,n){
    d[i][i]=0;
  }
  rep(i,0,m){
    int a,b;
    cin>>a>>b;
    ll c;
    cin>>c;
    if(c<=l){
      d[a-1][b-1]=c;
      d[b-1][a-1]=c;
    }
  }
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  
  rep(i,0,n){
    rep(j,0,n){
      if(d[i][j]>0 && d[i][j]<=l){
        d[i][j]=1;
      }
    }
  }
  
  rep(k,0,n){
    rep(i,0,n){
      rep(j,0,n){
        d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  
  int q;
  cin>>q;
  rep(i,0,q){
    int s,t;
    cin>>s>>t;
    if(d[s-1][t-1]==3e11) cout<<-1<<endl;
    else cout<<d[s-1][t-1]-1<<endl;
  }
}
