#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename T>
void read(T &x)
{
	x=0;char c=getchar();bool p=0;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')p=1;
	for(;c>='0'&&c<='9';c=getchar())x=x*10+(c^48);
	if(p)x=-x;
}
const int N=200006;
int n,m,q;
int head[N],pnt[N],nxt[N],E=0;
int vis[N],dfn[N],id[N],low[N],stck[N],top=0,cnt=0;
ll weight[N],ansid[N],dep[N];
void add_edge(int a,int b,ll c)
{
	pnt[E]=b;nxt[E]=head[a];weight[E]=c;head[a]=E++;
}
void tarjan(int u)
{
	dfn[u]=low[u]=++cnt;
	vis[u]=1;stck[++top]=u;
	for(int i=head[u],v;i!=-1;i=nxt[i])
	{
		v=pnt[i];
		if(!dfn[v])
		{
			tarjan(v);
			low[u]=min(low[u],low[v]);
		}
		else if(vis[v])
		{
			low[u]=min(low[u],dfn[v]);
		}
	}
	if(dfn[u]==low[u])
	{
		while(stck[top]!=u)
		{
			id[stck[top]]=u;
			vis[stck[top]]=0;
			--top;
		}
		vis[u]=0;
		id[u]=u;
		--top;
	}
}
ll gcd(ll x,ll y)
{
	if(y<0)return gcd(x,-y);
	if(!y)return x;
	return gcd(y,x%y);
}
void dfs(int rt,int u)
{
	if(id[u]!=rt)return;
	vis[u]=1;
	for(int i=head[u],v;i!=-1;i=nxt[i])
	{
		v=pnt[i];
		if(id[v]!=rt)continue;
		if(!vis[v])
		{
			dep[v]=dep[u]+weight[i];
			dfs(rt,v);
		}
		else
		{
			ll tp=dep[u]+weight[i]-dep[v];
			if(!ansid[rt])ansid[rt]=tp;else ansid[rt]=gcd(ansid[rt],tp);
		}
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	read(n);read(m);
	for(int i=1,u,v;i<=m;++i)
	{
		ll w;
		read(u);read(v);read(w);
		add_edge(u,v,w);
	}
	for(int i=1;i<=n;++i)
	{
		if(!dfn[i])
		{
			tarjan(i);
		}
	}
	memset(vis,0,sizeof(vis));
	for(int i=1;i<=n;++i)
	{
		if(i==id[i])
		{
			dep[i]=0;
			dfs(i,i);
		}
	}
	read(q);
	for(int i=1,v;i<=q;++i)
	{
		ll s,t;
		read(v);read(s);read(t);
		s=t-s;
		if(s%gcd(ansid[id[v]],t)!=0)printf("NO\n");else printf("YES\n");
	}
	return 0;
}//1919810