#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define ll long long
#define ln '\n'
#define F first
#define S second
void solve(){
int n, m, l, u, v, w;
cin >> n >> m >> l;
vector<vector<pair<int, ll>>>adj(n);
for (int i = 0; i < m; ++i) {
cin >> u >> v >> w;
u--, v--;
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
auto dijkstra = [&](){
vector<vector<int>>ans(n);
for (int src = 0; src < n; ++src) {
int cnt = 0;
vector<bool>vis(n);
vector<int>dis(n, 1e9);
priority_queue<tuple<int, int, int>>pq;
dis[src] = 0;
pq.push({0, l, src});
while (!pq.empty()){
if(cnt == n){ break; }
int dist, r_l, node;
tie(dist, r_l, node) = pq.top();
dist *= -1;
pq.pop();
if(vis[node]){ continue; }
cnt++;
vis[node] = 1;
for(auto neighbour : adj[node]){
int x = neighbour.F;
ll w = neighbour.S;
if(r_l >= w){
if(dist <= dis[x]){
dis[x] = dist;
pq.push({-dis[x], r_l - w, x});
}
} else {
if(w > l) { continue; }
if(dist + 1 <= dis[x]){
dis[x] = dist + 1;
pq.push({-dis[x], l - w, x});
}
}
}
}
ans[src] = dis;
}
return ans;
};
vector<vector<int>>ans = dijkstra();
int q; cin >> q;
while(q--){
cin >> u >> v;
u--, v--;
if(ans[u][v] == 1e9){
cout << -1 << ln;
continue;
}
cout << ans[u][v] << ln;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
#endif
int t_t = 1; //cin >> t_t;
while (t_t--){
solve();
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgYWxsKHYpIHYuYmVnaW4oKSwgdi5lbmQoKQojZGVmaW5lIHJhbGwodikgdi5yYmVnaW4oKSwgdi5yZW5kKCkKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBsbiAnXG4nCiNkZWZpbmUgRiBmaXJzdAojZGVmaW5lIFMgc2Vjb25kCgp2b2lkIHNvbHZlKCl7CiAgICBpbnQgbiwgbSwgbCwgdSwgdiwgdzsKICAgIGNpbiA+PiBuID4+IG0gPj4gbDsKICAgIHZlY3Rvcjx2ZWN0b3I8cGFpcjxpbnQsIGxsPj4+YWRqKG4pOwogICAgZm9yIChpbnQgaSA9IDA7IGkgPCBtOyArK2kpIHsKICAgICAgICBjaW4gPj4gdSA+PiB2ID4+IHc7CiAgICAgICAgdS0tLCB2LS07CiAgICAgICAgYWRqW3VdLmVtcGxhY2VfYmFjayh2LCB3KTsKICAgICAgICBhZGpbdl0uZW1wbGFjZV9iYWNrKHUsIHcpOwogICAgfQogICAgYXV0byBkaWprc3RyYSA9IFsmXSgpewogICAgICAgIHZlY3Rvcjx2ZWN0b3I8aW50Pj5hbnMobik7CiAgICAgICAgZm9yIChpbnQgc3JjID0gMDsgc3JjIDwgbjsgKytzcmMpIHsKICAgICAgICAgICAgaW50IGNudCA9IDA7CiAgICAgICAgICAgIHZlY3Rvcjxib29sPnZpcyhuKTsKICAgICAgICAgICAgdmVjdG9yPGludD5kaXMobiwgMWU5KTsKICAgICAgICAgICAgcHJpb3JpdHlfcXVldWU8dHVwbGU8aW50LCBpbnQsIGludD4+cHE7CiAgICAgICAgICAgIGRpc1tzcmNdID0gMDsKICAgICAgICAgICAgcHEucHVzaCh7MCwgbCwgc3JjfSk7CiAgICAgICAgICAgIHdoaWxlICghcHEuZW1wdHkoKSl7CiAgICAgICAgICAgICAgICBpZihjbnQgPT0gbil7IGJyZWFrOyB9CiAgICAgICAgICAgICAgICBpbnQgZGlzdCwgcl9sLCBub2RlOwogICAgICAgICAgICAgICAgdGllKGRpc3QsIHJfbCwgbm9kZSkgPSBwcS50b3AoKTsKICAgICAgICAgICAgICAgIGRpc3QgKj0gLTE7CiAgICAgICAgICAgICAgICBwcS5wb3AoKTsKICAgICAgICAgICAgICAgIGlmKHZpc1tub2RlXSl7IGNvbnRpbnVlOyB9CiAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgICAgIHZpc1tub2RlXSA9IDE7CiAgICAgICAgICAgICAgICBmb3IoYXV0byBuZWlnaGJvdXIgOiBhZGpbbm9kZV0pewogICAgICAgICAgICAgICAgICAgIGludCB4ID0gbmVpZ2hib3VyLkY7CiAgICAgICAgICAgICAgICAgICAgbGwgdyA9IG5laWdoYm91ci5TOwogICAgICAgICAgICAgICAgICAgIGlmKHJfbCA+PSB3KXsKICAgICAgICAgICAgICAgICAgICAgICAgaWYoZGlzdCA8PSBkaXNbeF0pewogICAgICAgICAgICAgICAgICAgICAgICAgICAgZGlzW3hdID0gZGlzdDsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBxLnB1c2goey1kaXNbeF0sIHJfbCAtIHcsIHh9KTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKHcgPiBsKSB7IGNvbnRpbnVlOyB9CiAgICAgICAgICAgICAgICAgICAgICAgIGlmKGRpc3QgKyAxIDw9IGRpc1t4XSl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBkaXNbeF0gPSBkaXN0ICsgMTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHBxLnB1c2goey1kaXNbeF0sIGwgLSB3LCB4fSk7CiAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgYW5zW3NyY10gPSBkaXM7CiAgICAgICAgfQogICAgICAgIHJldHVybiBhbnM7CiAgICB9OwogICAgdmVjdG9yPHZlY3RvcjxpbnQ+PmFucyA9IGRpamtzdHJhKCk7CiAgICBpbnQgcTsgY2luID4+IHE7CiAgICB3aGlsZShxLS0pewogICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgdS0tLCB2LS07CiAgICAgICAgaWYoYW5zW3VdW3ZdID09IDFlOSl7CiAgICAgICAgICAgIGNvdXQgPDwgLTEgPDwgbG47CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBjb3V0IDw8IGFuc1t1XVt2XSA8PCBsbjsKICAgIH0KfQoKaW50IG1haW4oKSB7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsKICAgIGNpbi50aWUoTlVMTCk7CiAgICBjb3V0LnRpZShOVUxMKTsKI2lmbmRlZiBPTkxJTkVfSlVER0UKICAgIGZyZW9wZW4oIm91dHB1dC50eHQiLCAidyIsIHN0ZG91dCk7CiNlbmRpZgogICAgaW50IHRfdCA9IDE7IC8vY2luID4+IHRfdDsKICAgIHdoaWxlICh0X3QtLSl7CiAgICAgICAgc29sdmUoKTsKICAgIH0KICAgIHJldHVybiAwOwp9