// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



pair <long long, long long> dis[310][310];



vector <pair<long long, long long>> ed[310];



void solve(long long v, long long l){

	

	priority_queue <pair<pair<long long, long long>, long long>> q;

	

	q.push(make_pair(make_pair(0, l), v));

	

	dis[v][v] = make_pair(0, l);

	

	while(!q.empty()){

		

		long long t = -q.top().first.first, c = q.top().first.second, x = q.top().second;

		

		q.pop();

		

		if(dis[v][x].first == t && dis[v][x].second == c){

			

			for(long long i = 0; i < (long long)ed[x].size(); i++){

				

				long long tx = t + (ed[x][i].second > c), cx = (ed[x][i].second > c) ? (l - ed[x][i].second) : (c - ed[x][i].second), xx = ed[x][i].first;

				

				if(cx < 0) continue;

				else if((dis[v][xx].first == -1) || ((dis[v][xx].first > tx) || ((dis[v][xx].first == tx) && (dis[v][xx].second < cx)))){

					q.push(make_pair(make_pair(-tx, cx), xx));

					dis[v][xx].first = tx;

					dis[v][xx].second = cx;

				}

			}

		}

	}

}

			

		

int main(){

	

	for(long long i = 0; i < 310; i++) for(long long j = 0; j < 310; j++) dis[i][j].first = -1;

	

	long long n, m, l;

	scanf("%lld %lld %lld", &n, &m, &l);

	

	for(long long i = 0; i < m; i++){

		long long u, v, x;

		scanf(" %lld %lld %lld", &u, &v, &x);

		

		ed[u].push_back(make_pair(v, x));

		ed[v].push_back(make_pair(u, x));

	}

	

	for(long long i = 0; i < n; i++) solve(i + 1, l);

	

	long long q;

	scanf(" %lld", &q);

	

	for(long long i = 0; i < q; i++){

		long long s, t;

		scanf(" %lld %lld", &s, &t);

		

		printf("%lld\n", dis[s][t].first);

	}

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 2.5776434177892096x):
#include<iostream>

#include<cstdio>

#include<cstring>

#include<cmath>

#include<algorithm>

#include<cstdlib>

#include<string>

#include<queue>

#include<map>

#include<vector>

#include<ctime>



#define int long long

#define R register

#define IL inline

#define Rf(a,b,c) for(R int (a)=(b);(a)<=(c);++(a))

#define Tf(a,b,c) for(R int (a)=(b);(a)>=(c);--(a))

#define MP make_pair

#define PA pair<int,int>

#define MES(a,b) memset((a),(b),sizeof((a)))

#define MEC(a,b) memcpy((a),(b),sizeof((b)))

#define D double



using namespace std;



const int N=305,inf=1e18;



int n,m,L,Q,w[N][N],c[N][N];



IL int read() {

    int x=0,f=1;char ch=getchar();

    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}

    while(ch>='0'&&ch<='9'){x*=10;x+=(ch-'0');ch=getchar();}

    return x*f;

}

IL void write(int x) {

    if(x<0) putchar('-'),x=-x;

    if(x>9) write(x/10);

    putchar(x%10+'0');

}



signed main()

{

	n=read();m=read();L=read();

	Rf(i,1,n) Rf(j,1,n) if(i!=j) w[i][j]=inf;

	Rf(i,1,m) {

		R int u=read(),v=read();

		w[u][v]=w[v][u]=read();

	}

	Rf(k,1,n) Rf(i,1,n) Rf(j,1,n) w[i][j]=min(w[i][j],w[i][k]+w[k][j]);

	Rf(i,1,n-1) Rf(j,i+1,n) {

		if(w[i][j]<=L) c[i][j]=c[j][i]=1;

		else c[i][j]=c[j][i]=inf;

	}

	Rf(k,1,n) Rf(i,1,n) Rf(j,1,n) c[i][j]=min(c[i][j],c[i][k]+c[k][j]);

	Q=read();

	while(Q--) {

		R int s=read(),t=read();

		if(c[s][t]==inf) write(-1);

		else write(c[s][t]-1);

		puts("");

	}

		

    return 0;

}