import std.stdio, std.algorithm, std.conv, std.string, std.array, std.math, std.range, std.container.dlist;

struct Way {
  int t1, t2, dist;
}
struct Query {
  int start, goal;
}

void main() {
  int N, M, L;
  readf(" %d %d %d ", &N, &M, &L);
  
  auto ways = new Way[M];
  foreach (ref way; ways) {
    readf(" %d %d %d ", &way.t1, &way.t2, &way.dist);
    --way.t1;
    --way.t2;
  }
  ways = ways.sort!"a.dist < b.dist".array;
  
  const Q = readln.chomp.to!int;
  auto queries = new Query[Q];
  foreach (ref query; queries) {
    readf(" %d %d ", &query.start, &query.goal);
    --query.start;
    --query.goal;
  }
  
  foreach (query; queries) {
    struct Town { bool fixed; int fuel_at_min_supply_count = 0, min_supply_count = int.max; }
    auto towns = new Town[N];
    
    struct Item { int town, fuel, supply_count; }
    DList!Item queue;
    queue.insertFront(Item(query.start, L, 0));
    
    for (; !queue.empty; queue.removeFront) {
      const front = queue.front;
      
      if (towns[front.town].fixed) continue;
      towns[front.town].fixed = true;
      if (front.town == query.goal) break;
      
      foreach (way; ways) {
        if (way.dist > L) continue;
        
        int t1 = way.t1, t2 = way.t2;
        if (t2 == front.town) swap(t1, t2);
        if (t1 != front.town || towns[t2].fixed) continue;
        
        auto fuel_before_leave         = front.fuel+0;
        auto supply_count_before_leave = front.supply_count+0;
        if (fuel_before_leave < way.dist) {
          fuel_before_leave = L;
          ++supply_count_before_leave;
        }
        
        const fuel_after_arrive = fuel_before_leave - way.dist;
        
        const is_min_supply_count = (towns[t2].min_supply_count >  supply_count_before_leave);
        const is_eq_supply_count  = (towns[t2].min_supply_count == supply_count_before_leave);
        const is_max_fuel         = (towns[t2].fuel_at_min_supply_count <  fuel_after_arrive);
        
        if (is_min_supply_count || (is_eq_supply_count && is_max_fuel)) {
          towns[t2].fuel_at_min_supply_count = fuel_after_arrive;
          towns[t2].min_supply_count         = supply_count_before_leave;
          queue.insertBack(Item(t2, fuel_after_arrive, supply_count_before_leave));
        }
      }
    }
    if (towns[query.goal].fixed) {
      towns[query.goal].min_supply_count.writeln;
    } else {
      (-1).writeln;
    }
  }
}