using namespace std;
#include <bits/stdc++.h>
#define N 200005
#define ll long long
ll gcd(ll a,ll b){
	ll k;
	while (b)
		k=a%b,a=b,b=k;
	return a;
}
int n,m;
struct EDGE{
	int to,w;
	EDGE *las;
} e[N];
int ne;
EDGE *last[N];
void link(int u,int v,int w){
	e[ne]={v,w,last[u]};
	last[u]=e+ne++;
}
int c[N],nc;
ll g[N];
int dfn[N],low[N],nowdfn;
int st[N],tp;
bool ins[N];
void tarjan(int x){
	low[x]=dfn[x]=++nowdfn;
	st[++tp]=x;
	ins[x]=1;
	for (EDGE *ei=last[x];ei;ei=ei->las)
		if (!dfn[ei->to])
			tarjan(ei->to),low[x]=min(low[x],low[ei->to]);
		else if (ins[ei->to])
			low[x]=min(low[x],dfn[ei->to]);
	if (dfn[x]==low[x]){
		++nc;
		while (st[tp]!=x){
			c[st[tp]]=nc;
			ins[st[tp--]]=0;
		}
		c[x]=nc;
		--tp,ins[x]=0;
	}
}
bool vis[N],bz[N];
ll f[N];
void dfs(int x){
	vis[x]=1;
	for (EDGE *ei=last[x];ei;ei=ei->las){
		if (c[ei->to]!=c[x]) continue;
		if (!vis[ei->to])
			f[ei->to]=f[x]+ei->w,dfs(ei->to);
		else
			g[c[x]]=gcd(g[c[x]],abs(f[x]+ei->w-f[ei->to]));
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;++i){
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		link(u,v,w);
	}
	for (int i=1;i<=n;++i)
		if (!dfn[i])
			tarjan(i);
	for (int i=1;i<=n;++i)
		if (!bz[c[i]]){
			bz[c[i]]=1;
			dfs(i);
		}
	int Q;
	scanf("%d",&Q);
	while (Q--){
		int v,s,t;
		scanf("%d%d%d",&v,&s,&t);
		int tmp=gcd(g[c[v]],t);
		if (s%tmp==0)
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}






























	