Language: C++

// unolight {{{
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(c) begin(c),end(c)
#define REP(i,n) for ( int i=0; i<(int)(n); i++ )
#define REP1(i,a,b) for ( int i=(int)(a); i<=(int)(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;

void RI() {}

template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}

template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) _dump(#__VA_ARGS__, __VA_ARGS__);

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
// }}}

const int MAX_N = 305;
const LL INF = 1e18;
int n, m, l;

LL dist[MAX_N][MAX_N];
LL fuel[MAX_N][MAX_N];

void input() {
    RI(n, m, l);
}

void init() {
    REP(i, n+1) {
        REP(j, n+1) {
            dist[i][j] = INF;
            fuel[i][j] = INF;
        }
        dist[i][i] = 0;
        fuel[i][i] = 0;
    }
}

void floyd_warshall(int n, LL A[MAX_N][MAX_N]) {
    REP1(i, 1, n) {
        REP1(j, 1, n) {
            REP1(k, 1, n) {
                A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
            }
        }
    }
}

void solve() {
    init();
    // read graph
    REP(i, m) {
        int a, b;
        LL c
        RI(a, b);
        scanf("%lld", &c);
        dist[a][b] = c;
        dist[b][a] = c;
    }
    
    floyd_warshall(n, dist);

    // REP(i, n) {
    //     REP(j, n) {
    //         printf("%d ", dist[i][j]);
    //     }
    //     printf("\n");
    // }

    REP1(i, 1, n) {
        REP1(j, 1, n) {
            if(i == j) continue;
            if(dist[i][j] <= l) {
                fuel[i][j] = 1LL;
            }
        }
    }
    // cout << "===" << endl;
    // REP(i, n) {
    //     REP(j, n) {
    //         printf("%d ", fuel[i][j]);
    //     }
    //     printf("\n");
    // }

    floyd_warshall(n, fuel);

    // REP(i, n) {
    //     REP(j, n) {
    //         printf("%d ", fuel[i][j]);
    //     }
    //     printf("\n");
    // }

    int Q;
    RI(Q);
    REP(i, Q) {
        int s, t;
        RI(s, t);
        if(fuel[s][t] >= INF) printf("-1\n");
        else printf("%lld\n", fuel[s][t]-1);
    }
}

int main( int argc, char *argv[] ) {
    input();
    solve();
    return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:97:9: error: expected initializer before 'RI'
   97 |         RI(a, b);
      |         ^~
a.cc:98:24: error: 'c' was not declared in this scope
   98 |         scanf("%lld", &c);
      |                        ^