#include <algorithm>
#include <iostream>
#define INF 1000000001

using namespace std;

void warshall_floyd(int d[][300], int n)
{
  for (int k = 0; k < n; k++){       // 経由点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

int main()
{
  int n, m, l;
  cin >> n >> m >> l;
  
  int d[300][300];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      d[i][j] = INF;
  
  int a, b, c;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b >> c;
    d[a-1][b-1] = c;
    d[b-1][a-1] = c;
  }
  
  warshall_floyd(d, n);
  
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      if (d[i][j] <= l)
        d[i][j] = 1;
      else
        d[i][j] = INF;
  
  warshall_floyd(d, n);
  
  int q;
  cin >> q;
  
  while (q--) {
    int s, t;
    cin >> s >> t;
    cout << (d[s-1][t-1] == INF ? -1 : d[s-1][t-1] - 1) << endl;
  }
}
