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>
using namespace std;

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};

const int SIZE=100000;
const int INF=1001001001001001001ll;
int N,M;
vector<edge>G[SIZE];
int dist_s[SIZE],dist_g[SIZE];

void dijkstra(int s,int *dist){
    fill_n(dist,N,INF);
    dist[s]=0;
    priority_queue<pint,vector<pint>,greater<pint>>que;
    que.push(pint(0,s));
    while(que.size()){
        int v,c;
        tie(c,v)=que.top();
        que.pop();
        if(dist[v]<c)continue;
        for(auto &e:G[v]){
            if(dist[e.to]<=c+e.cost)continue;
            dist[e.to]=c+e.cost;
            que.push(pint(dist[e.to],e.to));
        }
    }
}

vint bit[SIZE+1];
void bit_init(vpint &vec){
    rep(i,N){
        for(int k=i+1;k<=N;k+=k&-k)bit[k].pb(vec[i].se);
    }
    rep(i,N)sort(all(bit[i+1]));
}
int get(int k,int x){
    int ret=0;
    for(;k;k-=k&-k)ret+=bit[k].size()-(lower_bound(all(bit[k]),x)-bit[k].begin());
    return ret;
}

signed main(){
    scanf("%lld%lld",&N,&M);
    rep(i,M){
        int a,b,c;
        scanf("%lld%lld%lld",&a,&b,&c);
        G[a].pb(edge(b,c));
        G[b].pb(edge(a,c));
    }

    dijkstra(0,dist_s);
    dijkstra(N-1,dist_g);
    vpint vec;
    rep(i,N)vec.pb(pint(dist_s[i],dist_g[i]));
    sort(all(vec));
    bit_init(vec);

    int Q;scanf("%lld",&Q);
    while(Q--){
        int a,b;
        scanf("%lld%lld",&a,&b);
        int idx=lower_bound(all(vec),pint(a,INF))-vec.begin();
        printf("%lld\n",get(idx,b));
    }
    return 0;
}