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

#define rep(i,n) for(int i=0;i<(n);i++)
const int INF = 1e9+5;

int n, m, l, a, b, c, d[305][305];
void wf(){rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j],d[i][k] + d[k][j]);}

int main()
{
  scanf("%d%d%d",&n,&m,&l);
  fill(d[0], d[n], INF);
  
  rep(i,m){
    scanf("%d%d%d",&a,&b,&c);
    d[a-1][b-1] = d[b-1][a-1] = c;
  }
  wf();
  rep(i,n) rep(j,n) d[i][j] = (d[i][j] <= l ? 1 : INF);
  wf();
  scanf("%d",&c);
  rep(i,c){
    scanf("%d%d",&a,&b);
    printf("%d\n",d[a-1][b-1]==INF ? -1: d[a-1][b-1] - 1);
  }
}
