Problem: You are involved in the development of a certain game. The game is for players to explore randomly generated dungeons.

There are n rooms in the dungeon generated by this game, and they are numbered from 0 to n-1. The rooms are connected by a passage. There are m passages connecting rooms. The passage can go in either direction. In addition, a distance is set between the rooms. In the generated dungeon, it is possible to go from one room to all other rooms via several passages. Then, when the player plays the game, the 0th room is selected as the starting point and the n-1th room is selected as the goal point.

I want to set up a treasure chest in some room with items that will help users explore the dungeon. At that time, it is meaningless if it is too far from the starting point or too close to the goal point. Therefore, we would like to make a room that takes at least fg as a candidate for installing a treasure chest when we reach within the distance fs from the start and take the shortest path to reach the goal.

Given the generated dungeon and q. For q queries, count the number of candidate locations for treasure chests.



Input

The input is given in the following format.


n m
a1 b1 c1
..
..
..
am bm cm
q
fs1 fg1
..
..
..
fsq fgq


ai bi ci means that the distance of the passage connecting the rooms ai and bi is ci.

Input meets the following constraints
2 ≤ n ≤ 100,000
0 ≤ ai, bi <n
0 ≤ ci ≤ 100,000
n-1 ≤ m ≤ 100,000
1 ≤ q ≤ 100,000
0 ≤ fsi, fgi ≤ 260

Output

Print the answer value on one line for each query

Example

Input

4 4
0 1 3
1 3 4
0 2 2
2 3 1
4
0 0
2 2
2 1
3 4


Output

1
1
2
1

Solution (in CPP):

Solution:
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
typedef long long ll;
const ll INF = (ll)1e18;
struct Edge {
  int from, to, cost;
  Edge(int f, int t, int c) : from(f), to(t), cost(c) {}
};
struct State {
  int pos;
  ll cost;
  State(int p, ll c) : pos(p), cost(c) {}
  bool operator <(const State &other) const {
    return cost > other.cost;
  }
};
vector<ll> shortest_path(const vector<vector<Edge>> &G, int s) {
  vector<ll> d(G.size(), INF);
  priority_queue<State> Q;
  Q.emplace(s, 0);
  while(!Q.empty()) {
    State cur = Q.top(); Q.pop();
    if(d[cur.pos] > cur.cost) {
      d[cur.pos] = cur.cost;
      for(const Edge &e : G[cur.pos]) {
        Q.emplace(e.to, cur.cost + e.cost);
      }
    }
  }
  return d;
}
struct BIT {
  int N;
  vector<vector<int>> data;
  BIT(int n) : N(n), data(n + 1) {}
  void append(int a, int w) {
    ++a;
    for(int x = a; x <= N; x += x & -x) {
      data[x].push_back(w);
    }
  }
  void setup() {
    for(int a = 1; a <= N; ++a) sort(data[a].begin(), data[a].end());
  }
  int moreEq(int a, int w) {
    // index < a && value >= w
    int ret = 0;
    for(int x = a; x > 0; x -= x & -x) {
      ret += data[x].end() - lower_bound(data[x].begin(), data[x].end(), w);
    }
    return ret;
  }
};
int main() {
  ios::sync_with_stdio(false);
  int N, M; cin >> N >> M;
  vector<vector<Edge>> G(N);
  REP(i, M) {
    int a, b, c; cin >> a >> b >> c;
    G[a].emplace_back(a, b, c);
    G[b].emplace_back(b, a, c);
  }
  int Q; cin >> Q;
  vector<ll> fs(Q), fg(Q);
  REP(i, Q) cin >> fs[i] >> fg[i];
  vector<ll> ds = shortest_path(G, 0);
  vector<ll> dg = shortest_path(G, N - 1);
  set<ll> values;
  REP(i, Q) {
    values.insert(fs[i]);
    values.insert(fg[i]);
  }
  REP(i, N) {
    values.insert(ds[i]);
    values.insert(dg[i]);
  }
  map<ll, int> cmp;
  int index = 0;
  for(ll i : values) cmp[i] = index++;
  BIT bit(values.size()+1);
  REP(i, N) bit.append(cmp[ds[i]], cmp[dg[i]]);
  bit.setup();
  REP(q, Q) {
    cout << bit.moreEq(cmp[fs[q]] + 1, cmp[fg[q]]) << endl;
  }
}