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<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef pair<ll,ll> pll;

struct FenwickTree{
  int n;
  vi bit;
  FenwickTree(int x = 0):n(x){bit = vi(x+1,0);}

  inline void add(int i, int x){
    i++;
    while(i <= n){
      bit[i] += x;
      i += i & -i;
    }
  }

  inline int sum(int i){
    i++;
    int res = 0;
    while(i > 0){
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
};

void dijk(int s, const vector< vector<pll> > &g, vl &d){
  d[s] = 0;
  priority_queue< pll, vector<pll>, greater<pll> > q;
  q.push(pll(0,s));

  while(q.size()){
    ll cd = q.top().first;
    int v = q.top().second; q.pop();
    if(d[v]<cd)continue;

    for(pll e : g[v]){
      ll nd = cd + e.first;
      int u = e.second;
      if(d[u] > nd){
	d[u] = nd;
	q.push(pll(nd,u));
      }
    }
  }
}

int main(){
  int n,m;
  scanf("%d%d",&n,&m);

  vector< vector<pll> > g(n);
  rep(i,m){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    g[a].push_back(pll(c,b));
    g[b].push_back(pll(c,a));
  }

  vl ds(n,1e18), dg(n,1e18);
  dijk(0,g,ds); dijk(n-1,g,dg);
  
  vl vs;
  vector< vl > query;

  int q;
  scanf("%d",&q);
  rep(i,q){
    vl tmp(3); tmp[1] = i;
    scanf("%lld%lld",&tmp[2],&tmp[0]);
    query.push_back(tmp);
    vs.push_back(tmp[2]);
  }

  rep(i,n){
    vl tmp(3);
    tmp[0] = dg[i]; tmp[1] = q; tmp[2] = ds[i];
    query.push_back(tmp);
    vs.push_back(tmp[2]);
  }

  sort(all(query));
  reverse(all(query));
  sort(all(vs));
  vs.erase(unique(all(vs)),vs.end());

  vi ans(q);
  FenwickTree bit(vs.size());
  rep(i,query.size()){
    if(query[i][1] == q){
      int pos = lower_bound(all(vs),query[i][2]) - vs.begin();
      bit.add(pos,1);
    }else{
      int pos = lower_bound(all(vs),query[i][2]) - vs.begin();
      ans[query[i][1]] = bit.sum(pos);
    }
  }

  rep(i,q)printf("%d\n",ans[i]);
}