Problem: In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. 

There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an odometer that begins at s_i, increments for each mile driven, and resets to 0 whenever it reaches t_i. Phoenix has been tasked to drive cars along some roads (possibly none) and return them to their initial intersection with the odometer showing 0.

For each car, please find if this is possible. 

A car may visit the same road or intersection an arbitrary number of times. The odometers don't stop counting the distance after resetting, so odometers may also be reset an arbitrary number of times.

Input

The first line of the input contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5; 1 ≤ m ≤ 2 ⋅ 10^5) — the number of intersections and the number of roads, respectively.

Each of the next m lines contain three integers a_i, b_i, and l_i (1 ≤ a_i, b_i ≤ n; a_i ≠ b_i; 1 ≤ l_i ≤ 10^9) — the information about the i-th road. The graph is not necessarily connected. It is guaranteed that between any two intersections, there is at most one road for each direction.

The next line contains an integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of cars.

Each of the next q lines contains three integers v_i, s_i, and t_i (1 ≤ v_i ≤ n; 0 ≤ s_i < t_i ≤ 10^9) — the initial intersection of the i-th car, the initial number on the i-th odometer, and the number at which the i-th odometer resets, respectively.

Output

Print q answers. If the i-th car's odometer may be reset to 0 by driving through some roads (possibly none) and returning to its starting intersection v_i, print YES. Otherwise, print NO.

Examples

Input


4 4
1 2 1
2 3 1
3 1 2
1 4 3
3
1 1 3
1 2 4
4 0 1


Output


YES
NO
YES


Input


4 5
1 2 1
2 3 1
3 1 2
1 4 1
4 3 2
2
1 2 4
4 3 5


Output


YES
YES

Note

The illustration for the first example is below:

<image>

In the first query, Phoenix can drive through the following cities: 1 → 2 → 3 → 1 → 2 → 3 → 1. The odometer will have reset 3 times, but it displays 0 at the end.

In the second query, we can show that there is no way to reset the odometer to 0 and return to intersection 1.

In the third query, the odometer already displays 0, so there is no need to drive through any roads.

Below is the illustration for the second example: 

<image>

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Collection;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Collections;
import java.io.InputStream;
import java.util.BitSet;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        GPhoenixAndOdometers solver = new GPhoenixAndOdometers();
        solver.solve(1, in, out);
        out.close();
    }

    static class GPhoenixAndOdometers {
        long gcd(long a, long b) {
            while (a > 0 && b > 0) {
                if (a > b)
                    a %= b;
                else b %= a;
            }
            return a + b;
        }
        long Cycle;
        boolean dfs(int[] nodeID, int[] B, int[] C, List<Integer>[] graph, int node, long g, long phase, long[] cur) {
            int node_id = nodeID[node];
            if (cur[node_id] != -1) {
                if (cur[node_id] != phase){
                    Cycle = (phase - cur[node_id] + g) % g;
                    return false;
                }
                return true;
            }
            cur[node_id] = phase;
            for (int r : graph[node]) {
                int v = B[r];
                if (!dfs(nodeID, B, C, graph, v, g, (phase + C[r]) % g, cur)) return false;
            }
            return true;
        }

        boolean isGood(int[] nodeID, int[] B, int[] C, List<Integer>[] graph, int node, long g, int size) {
            long[] cur = new long[size];
            Arrays.fill(cur, -1);
            return dfs(nodeID, B, C, graph, node, g, 0, cur);
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            List<Integer>[] g = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);
            List<Integer>[] g2 = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);
            int[] A = new int[m], B = new int[m], C = new int[m];
            for (int i = 0; i < m; i++) {
                int a = in.readInt() - 1, b = in.readInt() - 1, c = in.readInt();
                g[a].add(b);
                A[i] = a;
                B[i] = b;
                C[i] = c;
            }
            int[] comp = new int[n];
            List<List<Integer>> components = new StronglyConnectedComponents().scc(g);
            int[] within = new int[n];
            int k = components.size();
            long [] G = new long[k];

            for (int i = 0; i < k; i++)
                for (int j : components.get(i))
                    comp[j] = i;

            for (int i = 0; i < m; i++) {
                if (comp[A[i]] == comp[B[i]]) {
                    g2[A[i]].add(i);
                }
            }

            for (int i = 0; i < k; i++) {
                List<Integer> nodes = components.get(i);
                List<Integer>[] temp = Stream.generate(ArrayList::new).limit(nodes.size()).toArray(List[]::new);
                for (int j = 0; j < nodes.size(); j++) within[nodes.get(j)] = j;
                for (int j = 0; j < nodes.size(); j++) {
                    for (int r : g2[nodes.get(j)])
                        temp[j].add(within[B[r]]);
                }
                int[] cycle = GraphCycleDetection.findCycle(temp);
                if (cycle == null) G[i] = 0;
                else {
                    long sum = 0;
                    for (int j = 0; j + 1 < cycle.length; j++) {
                        int u = nodes.get(cycle[j]), v = nodes.get(cycle[j + 1]);
                        for (int r : g2[u]) {
                            if (B[r] == v) {
                                sum += C[r];
                            }
                        }
                    }
                    G[i] = 1;
                    while(sum > 1){
                            if (isGood(within, B, C, g2, nodes.get(0), sum, nodes.size())) {
                                G[i] = sum;
                                break;
                            } else{
                                sum = gcd(sum, Cycle);
                            }
                        }
                }
            }

            int q = in.readInt();
            for (int i = 0; i < q; i++) {
                int v = in.nextInt() - 1, s = in.nextInt(), t = in.nextInt();
                int id = comp[v];
                if(G[id] == 0){
                    out.println(s == 0 ? "YES" : "NO");
                    continue;
                }
                out.println(s % gcd(G[id], t) == 0 ? "YES" : "NO");
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
            writer.print('\n');
        }

        public void close() {
            writer.close();
        }

    }

    static class GraphCycleDetection {
        public static int[] findCycle(List<Integer>[] graph) {
            int n = graph.length;
            int[] color = new int[n];
            int[] next = new int[n];
            for (int u = 0; u < n; u++) {
                if (color[u] != 0)
                    continue;
                int cycleStart = dfs(graph, u, color, next);
                if (cycleStart != -1) {
                    List<Integer> cycle = new ArrayList<>();
                    cycle.add(cycleStart);
                    for (int i = next[cycleStart]; i != cycleStart; i = next[i]) {
                        cycle.add(i);
                    }
                    cycle.add(cycleStart);
                    return cycle.stream().mapToInt(Integer::intValue).toArray();
                }
            }
            return null;
        }

        static int dfs(List<Integer>[] graph, int u, int[] color, int[] next) {
            color[u] = 1;
            for (int v : graph[u]) {
                next[u] = v;
                if (color[v] == 0) {
                    int cycleStart = dfs(graph, v, color, next);
                    if (cycleStart != -1) {
                        return cycleStart;
                    }
                } else if (color[v] == 1) {
                    return v;
                }
            }
            color[u] = 2;
            return -1;
        }

    }

    static class StronglyConnectedComponents {
        public static List<List<Integer>> scc(List<Integer>[] graph) {
            int n = graph.length;
            boolean[] used = new boolean[n];
            List<Integer> order = new ArrayList<>();
            for (int i = 0; i < n; i++)
                if (!used[i])
                    dfs(graph, used, order, i);

            List<Integer>[] reverseGraph = Stream.generate(ArrayList::new).limit(n).toArray(List[]::new);
            for (int i = 0; i < n; i++)
                for (int j : graph[i]) reverseGraph[j].add(i);

            List<List<Integer>> components = new ArrayList<>();
            Arrays.fill(used, false);
            Collections.reverse(order);

            for (int u : order)
                if (!used[u]) {
                    List<Integer> component = new ArrayList<>();
                    dfs(reverseGraph, used, component, u);
                    components.add(component);
                }

            return components;
        }

        static void dfs(List<Integer>[] graph, boolean[] used, List<Integer> res, int u) {
            used[u] = true;
            for (int v : graph[u])
                if (!used[v])
                    dfs(graph, used, res, v);
            res.add(u);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}