#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>
#include<stack>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> lltpl;

int dy8[8] = { 2,2,-2,-2,1,1,-1,-1 };
int dx8[8] = { 1,-1,1,-1,2,-2,2,-2 };
int dx4[4] = { 1,0,0,-1 };
int dy4[4] = { 0,1,-1,0 };


/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e17 + 7;
constexpr ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

// vector
template <typename T>
istream& operator>>(istream & is, vector<T> & vec) { for (T& x : vec) is >> x; return is; }
// pair
template <typename T, typename U>ostream& operator<<(ostream & os, pair<T, U> & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; }
// vector
template <typename T>ostream& operator<<(ostream & os, const vector<T> & vec) { os << "{";	for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; }
// map
template <typename T, typename U>ostream& operator<<(ostream & os, map<T, U> & map_var) { os << "{";	repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; }
// set
template <typename T>ostream& operator<<(ostream & os, set<T> & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; }


//以下はテンプレート化したもの
template<typename T> using Matrix = vector<vector<T> >;

template< typename T >
void warshall_floyd(Matrix<T>& g, T inf) {

	for (int k = 0; k < g.size(); k++)
	{
		for (int i = 0; i < g.size(); i++)
		{
			for (int j = 0; j < g.size(); j++)
			{
				if (g[i][k] == inf || g[k][j] == inf)
				{
					continue;
				}
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
			}
		}
	}
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll N, M, L;
	cin >> N >> M >> L;

	auto mp = make_v<ll>(N, N);
	fill_v(mp, LINF);
	

	vector<ll> A(M), B(M), C(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i] >> C[i];
		A[i]--;
		B[i]--;
		mp[A[i]][B[i]] = mp[B[i]][A[i]] = C[i];
		mp[A[i]][A[i]] = mp[B[i]][B[i]] = 0;
	}

	warshall_floyd(mp, LINF);
	int Q;
	cin >> Q;
	vector<ll> S(Q), T(Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> S[i] >> T[i];
		S[i]--;
		T[i]--;
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (mp[i][j] <= L) {
				mp[i][j] = 1;
			}
			else
			{
				mp[i][j] = LINF;
			}
		}
	}

	warshall_floyd(mp, LINF);

	for (int i = 0; i < Q; i++)
	{
		if (mp[S[i]][T[i]] == LINF) {
			cout << "-1" << endl;
		}
		else
		{
			cout << mp[S[i]][T[i]] - 1 << endl;
		}

	}

}


Measured memory_bytes: 3584