#include <bits/stdc++.h>
//#include <bits/extc++.h>

using namespace std;

//#define TEST 1
#define Maxn 1000000007
typedef long long ll;

using namespace std;

/****Simple Algo***********/
template<typename T>
int BS(int l, int r, T &&func)
{
    if (func(r)) return r+1;
    while (l<r) 
    {
        int mid = (l+r)>>1; 
        if (func(mid)) l = mid + 1; 
        else r = mid;
    }
    return l;
}
/***************************/
#define N 300010
ll a[N], vis[N];
vector<pair<int, int>> adj[N];

ll gcd(ll x, ll y) {return y==0? x : gcd(y, x%y);}

int ncc, seq;
int cc[N], anc[N], tim[N];
bool inStk[N];
ll dist[N], scc[N], cycle[N];
stack<int> stk;
void dfs(int x)
{
    tim[x] = anc[x] = ++seq;
    stk.push(x);
    inStk[x] = true;
    for (auto &p : adj[x])
    {
        int y = p.first, k = p.second;
        if (tim[y]==0)
        {
            dist[y] = dist[x] + k;
            dfs(y);
            anc[x] = std::min(anc[x], anc[y]);
        }
        else
        {
            if (inStk[y])
            {
                anc[x] = std::min(anc[x], tim[y]);
                //found a cycle.
                cycle[y] = gcd(cycle[y], dist[x]-dist[y]+k);
            }
        }
    }
    //the complete current scc
    if (tim[x]==anc[x])
    {
        inStk[x] = false;
        scc[ncc] = cycle[x];
        while (stk.top()!=x)
        {
            int y = stk.top();
            stk.pop();
            inStk[y] = false;
            cc[y] = ncc;
            scc[ncc] = gcd(scc[ncc], cycle[y]);
        }
        cc[/*x=*/stk.top()] = ncc;
        stk.pop();
        ncc++;
    }
}

void tarjian(int n)
{
    //init
    for (int i=0; i<=n; i++)
    {
        anc[i] = tim[i] = cc[i];
        dist[i] = cycle[i] = scc[i] = 0;
    }
    for (int i=0; i<=n; i++) inStk[i] = false;
    ncc = seq = 0;
    //dfs
    while (!stk.empty()) stk.pop();
    for (int i=1; i<=n; i++)
        if (tim[i]==0) dfs(i);
}

int main()
{
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i=1; i<=n; i++) adj[i].clear();
    for (int i=1; i<=m; i++)
    {
        int x, y, k;
        scanf("%d%d%d", &x, &y, &k);
        adj[x].emplace_back(y, k);
    }
    tarjian(n);
    //for (int i=1; i<=n; i++) cout<<i<<" "<<cc[i]<<" "<<cycle[i]<<endl;
    int q;
    scanf("%d", &q);
    while(q--)
    {
        int v, s, t;
        scanf("%d%d%d", &v, &s, &t);
        //cout<<cc[v]<<" "<<scc[cc[v]]<<" "<<gcd(scc[cc[v]], t)<<endl;
        if (s % gcd(scc[cc[v]], t)==0) printf("YES\n");
        else printf("NO\n");
    }

    return 0;
}