#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
using namespace std;
template<typename T1, typename T2>
ostream& operator << (ostream &i, pair<T1, T2> j) {
    return i << j.first << ' ' << j.second;
}
template<typename T>
ostream& operator << (ostream &i, vector<T> j) {
    i << '{' << j.size() << ':';
    for (T ii : j) i << ' ' << ii;
    return i << '}';
}
typedef long long ll;
typedef pair<int, int> pi;
vector<vector<pi>> g;
vector<int> cc, dep, low, stk;
vector<ll> d, v;
vector<bool> vis;
int _t;
void dfs(int i) {
    vis[i] = true;
    low[i] = dep[i] = _t++;
    stk.push_back(i);
    for (pi j : g[i]) if (cc[j.first] == -1) {
        if (!vis[j.first]) dfs(j.first);
        low[i] = min(low[i], low[j.first]);
    }
    if (low[i] == dep[i]) {
        while (stk.back() != i) cc[stk.back()] = v.size(), stk.pop_back();
        cc[i] = v.size(), stk.pop_back();
        v.push_back(0);
    }
}
void dfs2(int i, ll _d) {
    vis[i] = true, d[i] = _d;
    for (pi j : g[i]) if (!vis[j.first] && cc[j.first] == cc[i])
        dfs2(j.first, _d + j.second);
}
ll gcd(ll i, ll j) {
    return j ? gcd(j, i % j) : i;
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    g.resize(n), cc.assign(n, -1), dep.resize(n), low.resize(n), d.resize(n), vis.assign(n, false);
    for (int i = 0; i < m; ++i) {
        int x, y, z;
        cin >> x >> y >> z;
        --x, --y;
        g[x].emplace_back(y, z);
    }
    for (int i = 0; i < n; ++i) if (!vis[i]) dfs(i);
    vis.assign(n, false);
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) dfs2(i, 0);
        for (pi j : g[i]) if (cc[i] == cc[j.first])
            v[cc[i]] = gcd(v[cc[i]], abs(d[i] + j.second - d[j.first]));
    }
    int q;
    cin >> q;
    while (q--) {
        int x, y, z;
        cin >> x >> y >> z;
        z = gcd(z, v[cc[--x]]);
        cout << (y % z ? "NO\n" : "YES\n");
    }
}