#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 200005;
int n, m, q, fr[maxn], ed[maxn], len[maxn];
int last[maxn], Next[maxn], to[maxn], w[maxn], cnt;
inline void addedge(int x, int y, int z) {
	Next[++cnt] = last[x], last[x] = cnt;
	to[cnt] = y, w[cnt] = z;
}
int dfn[maxn], low[maxn], dft;
int st[maxn], top, ins[maxn];
int bel[maxn], tot;
ll G[maxn], dep[maxn];
void tarjan(int x) {
	dfn[x] = low[x] = ++dft;
	st[++top] = x, ins[x] = 1;
	for(int i = last[x]; i; i = Next[i]) {
		int v = to[i];
		if(!dfn[v]) {
			dep[v] = dep[x] + w[i];
			tarjan(v);
			low[x] = min(low[x], low[v]);
		}
		else if(ins[v]) low[x] = min(low[x], dfn[v]);
	}
	if(dfn[x] == low[x]) {
		ins[x] = 0;
		bel[x] = ++tot;
		while(st[top] != x) {
			int y = st[top--];
			ins[y] = 0;
			bel[y] = tot;
		}
		top--;
	}
}
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
		scanf("%d%d%d", &fr[i], &ed[i], &len[i]), addedge(fr[i], ed[i], len[i]);
	for(int i = 1; i <= n; i++)
		if(!dfn[i]) tarjan(i);
	for(int i = 1; i <= m; i++) {
		int x = fr[i], y = ed[i], z = len[i];
		if(bel[x] == bel[y]) 
			G[bel[x]] = gcd(G[bel[x]], llabs(dep[y] - dep[x] - z));
	}
	scanf("%d", &q);
	for(int i = 1, x, y, z; i <= q; i++) {
		scanf("%d%d%d", &x, &y, &z);
		x = bel[x];
		((z - y) % gcd(G[x], z) == 0) ? puts("YES") : puts("NO");
	}
	return 0;
}