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

#define maxn 301
#define inf 1e18
typedef long long ll;

ll n, m, l, d[maxn][maxn];
void floyd(){
  for(int k = 1; k <= n; k++){
    for(int i = 1; i <= n; i++){
      for(int j = 1; j <= n; j++){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main(){
  
  cin.sync_with_stdio(0), cin.tie(0);
  //~ freopen("in", "r", stdin);
  
  cin>>n>>m>>l;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= n; j++)
      d[i][j] = inf;
    d[i][i] = 0;
  }
      
  while(m--){
    int u, v, c;
    cin>>u>>v>>c;
    d[u][v] = d[v][u] = c;  
  }
  
  floyd();
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      if(d[i][j] > l) d[i][j] = inf;
      else d[i][j] = 1;   
    }
    d[i][i] = 0;
  }
  floyd();
  
  int q;
  cin>>q;
  
  while(q--){
    int u, v;
    cin>>u>>v;
    if(d[u][v] > n) cout<<-1<<endl;
    else cout<<d[u][v]-1<<endl;
  }
}
