Problem: In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. 

There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to 0 whenever it reaches t_i. Phoenix has been tasked to drive cars along some roads (possibly none) and return them to their initial intersection with the odometer showing 0.

For each car, please find if this is possible. 

A car may visit the same road or intersection an arbitrary number of times. The odometers don't stop counting the distance after resetting, so odometers may also be reset an arbitrary number of times.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ m ≤ 2 ⋅ 10^5) — the number of intersections and the number of roads, respectively.

Each of the next m lines contain three integers a_i, b_i, and l_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i; 1 ≤ l_i ≤ 10^9) — the information about the i-th road. The graph is not necessarily connected. It is guaranteed that between any two intersections, there is at most one road for each direction.

The next line contains an integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of cars.

Each of the next q lines contains three integers v_i, s_i, and t_i (1 ≤ v_i ≤ n; 0 ≤ s_i < t_i ≤ 10^9) — the initial intersection of the i-th car, the initial number on the i-th odometer, and the number at which the i-th odometer resets, respectively.

Output

Print q answers. If the i-th car's odometer may be reset to 0 by driving through some roads (possibly none) and returning to its starting intersection v_i, print YES. Otherwise, print NO.

Examples

Input


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


Output


YES
NO
YES


Input


4 5
1 2 1
2 3 1
3 1 2
1 4 1
4 3 2
2
1 2 4
4 3 5


Output


YES
YES

Note

The illustration for the first example is below:

<image>

In the first query, Phoenix can drive through the following cities: 1 → 2 → 3 → 1 → 2 → 3 → 1. The odometer will have reset 3 times, but it displays 0 at the end.

In the second query, we can show that there is no way to reset the odometer to 0 and return to intersection 1.

In the third query, the odometer already displays 0, so there is no need to drive through any roads.

Below is the illustration for the second example: 

<image>

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
const int maxn=1e6+7; long long dep[N],f1[N],f2[N],sum[N];
int n,m,fa[N],ft[N],xa[N],ya[N],za[N],FF[N]; vector<int>v[N],w[N],sq[N],v1[N],v2[N]; bool fl[N],fs[N];
inline long long gcd(long long a,long long b){
	if(!b) return a; return gcd(b,a%b);
}
struct node{
    int to,next,from;
}edge[N];
queue <int> q;
vector <int> cb[N];
vector <int> rdr[N];
int ans[N],totq,x,y,rd[maxn],u,vis[maxn],dis_[maxn],dis[maxn];
int dfn[N],low[maxn],f[maxn],times,cntqq;
int stack_[N],heads[N],visit[N],cnt,tot,index_;
void tarjan(int x)
{
    dfn[x]=low[x]=++times;
    stack_[++index_]=x;	
    visit[x]=1;
   	for(int i=0;i<v[x].size();i++)
    {
    	int u=v[x][i];
        if(!dfn[u])
        {
           	tarjan(u);
            low[x]=min(low[x],low[u]);
       	}
       	else 
        if(visit[u])
        low[x]=min(low[x],dfn[u]);
    }
    if(low[x]==dfn[x])
   	{
   		tot++;//强连通分量编号 
   		while(1)
       	{
       		vis[stack_[index_]]=tot;
       		dis_[tot]+=dis[stack_[index_]];	
       		visit[stack_[index_]]=0;index_--;
       		if(x==stack_[index_+1])break;
       	}
    }
}
inline void dfs(int u){
	fl[u]=1;
	for(int i=0;i<v[u].size();i++){
		int x=v[u][i]; if(vis[u]!=vis[x]||fl[x]) continue;
		fa[x]=u,ft[x]=w[u][i],dep[x]=dep[u]+ft[x],dfs(x);
		FF[sq[u][i]]=1;
	}
}
inline void dfs2(int u){
	fl[u]=1;
	for(int i=0;i<v1[u].size();i++){
		int x=v1[u][i]; if(vis[u]!=vis[x]) continue;
//		cout<<u<<","<<x<<endl;
		if(!fl[x]){
			dep[x]=dep[u]+v2[u][i]; dfs2(x);
		}
		else{
			sum[vis[u]]=gcd(sum[vis[u]],v2[u][i]+dep[u]-dep[x]);
		}
	}
}
int main(){
	scanf("%d%d",&n,&m); int a,b,c;
	for(int i=1;i<=m;i++) scanf("%d%d%d",&a,&b,&c),v[a].push_back(b),w[a].push_back(c),sq[a].push_back(i),xa[i]=a,ya[i]=b,za[i]=c;
	for(int i=1;i<=n;i++) if(!dfn[i])tarjan(i);
	for(int i=1;i<=n;i++) if(!fl[i]) dfs(i),fs[i]=1;
	for(int i=1;i<=m;i++){
		a=xa[i],b=ya[i],c=za[i];
		v1[a].push_back(b),v2[a].push_back(c);
		v1[b].push_back(a),v2[b].push_back(-c);
	}
	memset(fl,0,sizeof(fl));
	for(int i=1;i<=n;i++) if(!fl[i]) dfs2(i);
	int q; cin>>q;
//	cout<<sum[vis[10]]<<endl;
	while(q--){
		scanf("%d%d%d",&a,&b,&c); int P=gcd(b,c);
		a=vis[a];
		if(b==0) puts("YES");
		else if(sum[a]==0) puts("NO");
		else if(P%gcd(c,sum[a])==0)  puts("YES");
		else puts("NO");
	}
}
//10 10
//8 2 5
//4 10 2
//10 4 3
//10 7 7
//2 5 10
//10 1 6
//3 9 7
//3 10 7
//9 1 9
//6 8 8
//1
//10 1 4