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<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reg(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=(b);i>=(a);i--)
typedef long long int lli;
typedef pair<lli,lli> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX


int dijkstra(int n,int s,vector<mp>* vs,lli* dist,int g=-1){
	memset(dist,-1,sizeof(lli)*n);
	//rep(i,n)dist[i]=-1;
	priority_queue<mp,vector<mp>,greater<mp> > que;
	que.push(mp(0,s));
	while(!que.empty()){
		mp pa=que.top();
		que.pop();
		lli co=pa.fir,
			no=pa.sec;
		if(dist[no]!=-1 && dist[no]<co)continue;
		dist[no]=co;
		if(no==g)return co;
		rep(i,vs[no].size()){
			mp pb=vs[no][i];
			lli to=pb.fir,
				tc=co+pb.sec;
			if(dist[to]!=-1 && dist[to]<=tc)continue;
			dist[to]=tc;
			que.push(mp(tc,to));
		}
	}
	return -1;
}


int n,m,N;
vector<mp> vs[100005];
lli ds[100005];
lli dt[100005];
mp dats[100005];

vector<lli> bit[400005];

void set(int p){//to 1-index
	int td = p;
	//printf("%d %d %d\n",p,dats[p].fir,dats[p].sec);
	p++;
	while(p<=N){
		bit[p].push_back(dats[td].sec);
		p += (p&(-p));
	}
}

void init(){
	N=1;
	while(N<=n+5)N*=2;
	
	rep(i,n){
		set(i);
	}
	reg(i,1,N){
		sort(bit[i].begin(),bit[i].end());
	}
}

int query(lli p,lli q){
	int st = upper_bound(ds,ds+n,p)-ds;
	//printf("que .. p .. %d is %d\n",p,st);
	//st--daga,1-indexednanodest++de.
	int res = 0;
	while(st>0){
		vector<lli>& nv = bit[st];
		int on = (lower_bound(nv.begin(),nv.end(),q)  - nv.begin()); //if(on>0)on--;
		
		//printf("on .. st .. %d q .. %d is %d\n",st,q,on);
		//rep(i,nv.size())printf("%d ",nv[i]);
		//printf("\nsiz .. %d\n",((int)nv.size()));
		res += nv.size() - on;
		st -= (st&(-st));
	}
	return res;
}

int main(void){
	/*
	int ha[5]={1,3,3,4,4};
	printf("%d %d\n",lower_bound(ha,ha+5,2)-ha,upper_bound(ha,ha+5,2)-ha);
	*/
	scanf("%d%d",&n,&m);
	rep(i,m){
		lli a,b,c;
		scanf("%lld%lld%lld",&a,&b,&c);
		vs[a].push_back(mp(b,c));
		vs[b].push_back(mp(a,c));
	}
	
	dijkstra(n,0,vs,ds);
	dijkstra(n,n-1,vs,dt);
	
	rep(i,n){
		dats[i] = mp(ds[i],dt[i]);
		//printf("dists .. %d %d %d\n",i,ds[i],dt[i]);
	}
	sort(dats,dats+n);
	sort(ds,ds+n);
	
	init();
	
	int iq;
	scanf("%d",&iq);
	rep(i,iq){
		lli a,b;
		scanf("%lld%lld",&a,&b);
		printf("%d\n",query(a,b));
	}
	
	return 0;
}