#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))
#define MAX(x,y) ((x)<(y)?(y):(x))

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
*/

int main()
{
	ll i,j,k;
	ll N,M,L;
	ll mp[512][512] = {0};
	vector<ll> w[512];
	ll en[512][512] = {0};
	cin >> N >>M >> L;
	for(i=0;i<N;++i)
	for(j=0;j<N;++j)
	{
		if(i==j)
		{
			mp[i][j] = 0;
			en[i][j] = 0;
		}
		else
		{
			mp[i][j] = 10000000000000;
			en[i][j] = 10000000000000;
		}
	}
	for(k=0;k<M;++k)
	{
		cin >> i >> j;
		--i;--j;
		cin >> mp[i][j];
		mp[j][i] = mp[i][j];
		w[i].push_back(j);
		w[j].push_back(i);
	}
	for(i=0;i<N;++i)
	{
		queue<pair<ll, ll> > q;
		q.push(make_pair(i, L));
		while(!q.empty())
		{
			auto tp = q.front();
			q.pop();
			for(j=0;j<w[tp.first].size();j++)
			{
				if( tp.second >= mp[tp.first][w[tp.first][j]])
				{
					if( en[i][w[tp.first][j]] ==  10000000000000 || en[i][w[tp.first][j]] < tp.second - mp[tp.first][w[tp.first][j]])
					{
						en[i][w[tp.first][j]] = tp.second - mp[tp.first][w[tp.first][j]];
						q.push(make_pair(w[tp.first][j], tp.second - mp[tp.first][w[tp.first][j]]));
					}
				}
			}
		}
		for(j=0;j<N;++j)
		{
			if(en[i][j] != 10000000000000)
				en[i][j] = 1;
		}
	}
	/*
	for(i=0;i<N;++i)
	{
		for(j=0;j<N;++j)
		{
			cout << en[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for(k=0;k<N;++k)
	for(i=0;i<N;++i)
	for(j=0;j<N;++j)
	{
		if(en[i][j] > en[i][k] + en[k][j])
		{
			en[i][j] = en[i][k] + en[k][j];
		}
	}
	ll Q;
	cin >>Q;
	for(i=0;i<Q;++i)
	{
		cin >> k >> j;
		if(en[k-1][j-1] == 10000000000000)
			cout << -1 << endl;
		else
			cout << en[k-1][j-1]-1 << endl;
	}
	return 0;
}




















Measured memory_bytes: 5760