#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cassert>

#include<cmath>
#include<functional>
#include<algorithm>

#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<bitset>
#include<tuple>

#define TEST {IS_TEST=true;}

using namespace std;
using ll = int;
using v_bool = vector <bool>;
using v_ll = vector <ll>;
using v_std = vector <string>;
using p_ll = pair <ll,ll>;
using vv_ll = vector <vector <ll> >;
using vp_ll = vector < p_ll >;

bool IS_TEST=false;
ll ll_min=1<<31;
ll ll_max=~ll_min;
ll MOD = 1000000007;

/*
template<class T> bool show_nl(const T&){ return true;}
bool show_nl(const ll&){ return false;}
template<class T,class S> bool show_nl(const pair<T,S>&){ return false;}
*/

template<class T> bool show_nl(const T&){ return false;}
bool show_nl(const string&){ return true;}
template<size_t N> bool show_nl(const bitset<N>&){ return true;}
template<class T> bool show_nl(const vector<T>&){ return true;}
template<class T,class S> bool show_nl(const queue<T,S>&){ return true;}
template<class T,class S,class U> bool show_nl(const priority_queue<T,S,U>&){ return true;}
template<class T,class S> bool show_nl(const stack<T,S>&){ return true;}
template<class T,class S> bool show_nl(const set<T,S>&){ return true;}
template<class T,class S> bool show_nl(const multiset<T,S>&){ return true;}
template<class T> bool show_nl(const unordered_set<T>&){ return true;}
template<class T,class S,class U> bool show_nl(const map<T,S,U>&){ return true;}
template<class T,class S,class U> bool show_nl(const multimap<T,S,U>&){ return true;}
template<class T,class S> bool show_nl(const unordered_map<T,S>&){ return true;}

template<class T> void show(const T& x,bool newline=false){
  if (!IS_TEST) return;
  cout << x; if (newline) cout << " <#>" <<  endl;
}
void show(const string& x,bool newline=true){
  if (!IS_TEST) return;
  cout << x; if (newline) cout << endl;
}
template<class T,class S> void show(const pair<T,S>& x,bool newline=false){
  if (!IS_TEST) return;
  cout << "{ " << x.first << " " << x.second << " }";
  if (newline) cout << " <#>" <<  endl;
}
template<class T> void show_common3(const T&x){
  if (!IS_TEST) return;
  auto itr=x.begin();
  if (x.begin()==x.end()) {cout<<"<NULL>"<<endl;return;}
  if (show_nl(*itr)){
    cout << "--------------------------------" << endl;
    auto itr=x.begin();
    while(itr!=x.end()){ show(*itr); itr++;}
    cout << "--------------------------------" << endl;
  }else{
    if (itr==x.end()){ cout<<endl; return;}
    while(true){
      show(*itr);itr++;
      if (itr==x.end()) break; else cout << " ";
    }
    cout << endl;
  }
}
template<class T> void show(const vector<T>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const set<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const multiset<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T> void show(const unordered_set<T>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S,class U> void show(const map<T,S,U>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S,class U> void show(const multimap<T,S,U>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}
template<class T,class S> void show(const unordered_map<T,S>& x,bool newline=false){
  if (!IS_TEST) return; show_common3(x);
}

void load(ll& x){ cin >> x;}
void load(string& x){ cin >> x;}
void load(v_ll& v,ll b,ll e){
    v.assign(e+1,0);
    for(ll i=b;i<e;i++)cin >> v[i];
}
v_ll loadvec0(ll n){
    v_ll v(n+1,0);
    for(ll i=0;i<n;i++)cin >> v[i];
    return v;
}
v_ll loadvec1(ll n){
    v_ll v(n+2,0);
    for(ll i=1;i<=n;i++)cin >> v[i];
    return v;
}

void disp(const ll& x){ cout << x << endl;}
void disp(const string& x){ cout << x << endl;}
void disp(const v_ll& v,ll b,ll e){
    for(ll i=b;i<e;i++){
        if (i!=b) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

v_ll arange(ll n){
    v_ll v(n+1,0);
    for(ll i=0;i<=n;i++)v[i]=i;
    return v;
}

ll vec_sum(const v_ll& v,ll b,ll e){
    ll ans=0;
    for(ll i=b;i<e;i++)ans+=v[i];
    return ans;
}


ll max(ll x,ll y){return x>y?x:y;}
ll max(ll x,ll y, ll z){return max(max(x,y),z);}
ll max(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) {ans=max(ans,*b);b++;}
    return ans;
}

ll min(ll x,ll y){return x>y?x:y;}
ll min(ll x,ll y, ll z){return min(min(x,y),z);}
ll min(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) {ans=min(ans,*b);b++;}
    return ans;
}

ll mid(ll x,ll y,ll z){
    if (y>=x && x>=z) return x;
    if (z>=x && x>=y) return x;
    if (x>=y && y>=z) return y;
    if (z>=y && y>=x) return y;
    if (x>=z && z>=y) return z;
    if (y>=z && z>=x) return z;
    return x;
}

ll gcd(ll x,ll y){
    if(x<0)x=-x; if(y<0)y=-y;
    while(y>0){ x%=y; swap(x,y); }
    return y;
}
ll gcd(ll x,ll y, ll z){return gcd(gcd(x,y),z);}
ll gcd(v_ll::iterator b,v_ll::iterator e){
    ll ans=0;
    while (b<e) ans=gcd(ans,*b);
    return ans;
}

ll lcm(ll x,ll y){
    ll z=x*y; if(x<0)x=-x; if(y<0)y=-y;
    while(y>0){ x%=y; swap(x,y); }
    return z/y;
}
ll lcm(ll x,ll y, ll z){return lcm(lcm(x,y),z);}
ll lcm(v_ll::iterator b,v_ll::iterator e){
    ll ans=1;
    while (b<e) ans=lcm(ans,*b);
    return ans;
}

ll v_sum(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans+=*b; b++;}
    return ans;
}
ll v_xor(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans^=*b; b++;}
    return ans;
}
ll v_eq(v_ll::iterator b,v_ll::iterator e){
    ll ans=*b;
    while (b<e) { ans^=~*b; b++;}
    return ans;
}


template<class T> void refl_max(T& x,const T& y){ if (x>=y) return; x=y; }
template<class T> void refl_min(T& x,const T& y){ if (x<=y) return; x=y; }

template<class T,class S> void refl_max(T& x,const T& y,S& xx,const S& yy){
  if (x>=y) return; x=y; xx=yy;
}
template<class T,class S> void refl_min(T& x,const T& y,S& xx,const S& yy){
  if (x<=y) return; x=y; xx=yy;
}

/*O(logN)*/
ll sqrt_ll(ll n){
  assert(n>=0);
  ll ok = 0,ng = n+1;
  while(ok-ng>1||ng-ok>1){ ll m=(ok+ng)/2; if (m*m<=n) ok=m; else ng=m;}
  return ok;
}

class Neighbor{
    public:
    bool dir;
    ll from,to,edge;
    Neighbor(ll w,ll x,ll y,bool z){from=w;to=x;edge=y;dir=z;}
    inline constexpr operator ll()const{ return to;} 
};
class Node{
    public:
    vector<Neighbor> neighbor;
    bool valid; ll idx;
    Node(bool v,ll i){valid=v;idx=i;}
    inline constexpr Neighbor& operator[](ll n){ return neighbor[n];}
    inline vector<Neighbor>::iterator begin(){ return neighbor.begin();}
    inline vector<Neighbor>::iterator end(){ return neighbor.end();}
    inline constexpr void push_back(ll w,ll x,ll y, bool z){neighbor.push_back(Neighbor(w,x,y,z));}
    inline constexpr ll size(){return neighbor.size();}
    /*----------------*/
};
class Edge{
    public:
    bool valid;  bool indir;
    ll n1,n2; ll idx;
    Edge(bool v,ll i,ll x,ll y,bool z){valid=v;idx=i;n1=x;n2=y;indir=z;}
    /*----------------*/

};
class Graph{
    public:
    vector<Node> n;
    vector<Edge> e;
    void init(ll nodes, ll idx_node, ll idx_edge){
        n.clear(); e.clear();
        for (ll i=0;i<idx_node;i++) n.push_back(Node(false,n.size()));
        for (ll i=0;i<idx_edge;i++) e.push_back(Edge(false,e.size(),-1,-1,true));
        for (ll i=0;i<nodes;i++) n.push_back(Node(true,n.size()));
    }
    ll edge(ll f, ll t, bool indir=true){
        assert(f>=0&&f<n.size()&&t>=0&&t<n.size());
        ll i=e.size();e.push_back(Edge(true,i,f,t,!indir));
        n[f].push_back(f,t,i,true);
        n[t].push_back(t,f,i,indir);
        return i;
    }
    ll d_edge(ll f, ll t){return edge(f,t,false);}
    inline constexpr Node& operator[](ll x){ return n[x];} 

    void show(){
        for (ll i=0;i<n.size();i++){
            if(!n[i].valid)continue;
            cout << i << "\t";
            for(ll j=0;j<n[i].size();j++){
                if (n[i][j].dir) cout << n[i][j].to << " ";
            }
            cout << endl;
        }
    }
    /*----------------*/
};

using tp_l3=pair<pair<ll,ll>,ll>;//tuple<ll,ll,ll>;


ll N,M,L,Q;
vv_ll S;
vv_ll B;
v_ll C;
int main(){
  cin >> N>>M>>L;
  Graph G;
  C.assign(M+1,0);
  S.assign(N+1,v_ll(N+1,-1));
  B.assign(N+1,v_ll(N+1,ll_min));
  G.init(N,1,1);
  for (ll i=1;i<=M;i++){
    ll a,b,c;
    cin >> a >> b >> c;
    G.edge(a,b);
    C[i]=c;
  }
  for (ll s=1;s<=N;s++){
  priority_queue<tp_l3> que;
  v_bool A(N+1,false);
  que.push(tp_l3(p_ll(0,L),s));
  while(!que.empty()){
    tp_l3 ff=que.top();
    ll f0=ff.first.first;
    ll f1=ff.first.second;
    ll f=ff.second;
    que.pop();
    if (A[f]) continue;
    A[f]=true;
    S[s][f]=-f0;
    for(ll i=0;i<G[f].size();i++){
      ll t=G[f][i];
      ll w = C[G[f][i].edge];
      if (A[t]!=true){
        if (f1>=w){
        if (B[s][t]<=f0){
          que.push(tp_l3(make_pair(f0,f1-w),t));
          B[s][t]=f0;
        }
        }
        else if (w>L){}
        else
        {
          if (B[s][t]<=f0-1){
          que.push(tp_l3(make_pair(f0-1,L-w),t));
          B[s][t]=f0-1;
          }
        }
      }
    }
  }
  }
  cin >> Q;
  for(ll i=0;i<Q;i++){
    ll x,y;
    cin >> x >> y;
    cout << S[x][y] << "\n";
  }
}




Measured memory_bytes: 4852