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<queue>
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef long long ll;

const ll INF=1LL<<61;
const int V_MAX=100000;

struct edge{ int v,cost; };

void pairsort(int n,ll *a,ll *b){
	static pair<ll,ll> c[V_MAX];
	rep(u,n) c[u]=make_pair(a[u],b[u]);
	sort(c,c+n);
	rep(u,n) a[u]=c[u].first, b[u]=c[u].second;
}

template<class T>
class segment_tree{
	static const int N_MAX=1<<17;
	int n;
	vector<T> dat[2*N_MAX];

	int query(int l,int r,int a,int b,int u,ll key){
		if(l<=a && b<=r) return dat[u].end()-lower_bound(dat[u].begin(),dat[u].end(),key);

		int res=0;
		int c=(a+b+1)/2;
		if(l<c && a<r) res+=query(l,r,a,c,2*u  ,key);
		if(l<b && c<r) res+=query(l,r,c,b,2*u+1,key);
		return res;
	}

public:
	void build(int N,const T *a){
		for(n=1;n<N;n*=2);
		rep(u,2*n) dat[u].clear();
		rep(i,n) dat[n+i].push_back(a[i]);
		for(int u=n-1;u>=1;u--){
			int l=2*u,r=2*u+1;
			dat[u].resize(dat[l].size()+dat[r].size());
			merge(dat[l].begin(),dat[l].end(),dat[r].begin(),dat[r].end(),dat[u].begin());
		}
	}

	int query(int l,int r,ll key){ return query(l,r,0,n,1,key); }
};

int main(){
	int n,m; scanf("%d%d",&n,&m);
	static vector<edge> G[V_MAX];
	rep(i,m){
		int u,v,cost; scanf("%d%d%d",&u,&v,&cost);
		G[u].push_back((edge){v,cost});
		G[v].push_back((edge){u,cost});
	}

	static ll ds[V_MAX],dg[V_MAX]; // d_start, d_goal
	rep(t,2){
		ll *d=(t==0?ds:dg);
		int s=(t==0?0:n-1);
		rep(u,n) d[u]=(u==s?0:INF);
		priority_queue< pair<ll,int> > Q; Q.push(make_pair(0,s));
		while(!Q.empty()){
			ll d_now=-Q.top().first;
			int u=Q.top().second; Q.pop();

			if(d[u]<d_now) continue;

			rep(i,G[u].size()){
				int v=G[u][i].v,cost=G[u][i].cost;
				if(d[v]>d[u]+cost){
					d[v]=d[u]+cost;
					Q.push(make_pair(-d[v],v));
				}
			}
		}
	}

	pairsort(n,ds,dg);

	static segment_tree<ll> S;
	S.build(n,dg);

	int q; scanf("%d",&q);
	while(q--){
		ll a,b; scanf("%lld%lld",&a,&b);
		int i=upper_bound(ds,ds+n,a)-ds;
		printf("%d\n",S.query(0,i,b));
	}

	return 0;
}