#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define pii pair<int, LL>

const int maxN = 3e5 + 10;

int n, m, q;
int cnt, low[maxN + 1], dfn[maxN + 1];
int stk[maxN + 1], top;
int scc[maxN + 1], res;
LL ans[maxN + 1], dep[maxN + 1];

vector<pii> to[maxN + 1];

inline LL gcd(LL a, LL b)
{
	while(b)
	{
		LL r = a % b;
		a = b, b = r;
	}
	return a;
}

inline void tarjan(int u)
{
	stk[++ top] = u;
	dfn[u] = low[u] = ++ cnt;
	for(int i = 0; i < to[u].size(); i++)
	{
		int v = to[u][i].first, w = to[u][i].second;
		if(w < 0) continue;
		if(!dfn[v]) tarjan(v), low[u] = min(low[u], low[v]);
		else if(!scc[v]) low[u] = min(low[u], dfn[v]);
	}
	if(low[u] == dfn[u])
	{
		res ++;
		while(stk[top] != u) scc[ stk[top --] ] = res;
		scc[ stk[top --] ] = res;
	}
}

inline void dfs(int u)
{
	dfn[u] = ++ cnt;
	for(int i = 0; i < to[u].size(); i++)
	{
		int v = to[u][i].first, w = to[u][i].second;
		if(scc[v] != scc[u]) continue;
		if(!dfn[v]) dep[v] = dep[u] + w, dfs(v);
		else ans[ scc[u] ] = gcd(ans[ scc[u] ], dep[u] - dep[v] + w); 
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		int x, y, t;
		scanf("%d %d %d", &x, &y, &t);
		to[x].push_back( pii(y, t) );
		to[y].push_back( pii(x, -t) );
	}

	for(int i = 1; i <= n; i++)
		if(!dfn[i]) tarjan(i);

	cnt = 0;
	for(int i = 1; i <= n; i++) dfn[i] = 0;
	for(int i = 1; i <= n; i++)
		if(!dfn[i]) dfs(i);

	scanf("%d", &q);
	while(q --)
	{
		int u, s, t;
		scanf("%d %d %d", &u, &s, &t);
		if(!s) { puts("YES"); continue; }
		if(!ans[ scc[u] ]) { puts("NO"); continue; }
		int r = t - s;
		LL g = gcd(ans[ scc[u] ], t);
		puts(r % g == 0 ? "YES" : "NO");
	}
	return 0;
}
