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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.StringTokenizer;

public final class G {

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    static List<List<int[]>> g1;
    static List<List<int[]>> g2;

    public static void main(String[] args) {
        final FastScanner fs = new FastScanner();
        final int n = fs.nextInt();
        final int m = fs.nextInt();
        g1 = new ArrayList<>(n);
        g2 = new ArrayList<>(n);
        for (int i = 0; i < n; i++) {
            g1.add(new ArrayList<>());
            g2.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            final int u = fs.nextInt() - 1;
            final int v = fs.nextInt() - 1;
            final int w = fs.nextInt();
            g1.get(u).add(new int[] { v, w });
            g2.get(v).add(new int[] { u, w });
        }
        final List<Integer> topSort = new ArrayList<>(n);
        boolean[] seen = new boolean[n];
        for (int i = 0; i < n; i++) {
            dfs1(i, seen, topSort);
        }
        int ccNum = 0;
        seen = new boolean[n];
        final int[] cc = new int[n];
        final int[] ccRoot = new int[n];
        Arrays.fill(cc, -1);
        for (int i = n - 1; i >= 0; i--) {
            final int u = topSort.get(i);
            if (cc[u] == -1) {
                dfs2(u, seen, cc, ccNum);
                ccRoot[ccNum++] = u;
            }
        }
        final long[] depth = new long[n];
        Arrays.fill(depth, -1);
        final long[] gcd = new long[n];
        for (int i = 0; i < ccNum; i++) {
            dfs3(ccRoot[i], 0, depth, gcd, cc);
        }
        final int q = fs.nextInt();
        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            final int u = fs.nextInt() - 1;
            final int s = fs.nextInt();
            final int t = fs.nextInt();
            final int ccIdx = cc[u];
            if (gcd[ccIdx] == 0) {
                sb.append(s == 0 ? "YES\n" : "NO\n");
            } else {
                final long currGcd = gcd(gcd[ccIdx], t);
                sb.append(s % currGcd == 0 ? "YES\n" : "NO\n");
            }
        }
//        System.out.println(Arrays.toString(gcd));
//        System.out.println(Arrays.toString(cc));
//        System.out.println(Arrays.toString(ccRoot));
        System.out.println(sb);
    }

    private static void dfs1(int u, boolean[] seen, List<Integer> topSort) {
        if (seen[u]) {
            return;
        }
        seen[u] = true;
        for (int[] v : g1.get(u)) {
            dfs1(v[0], seen, topSort);
        }
        topSort.add(u);
    }

    private static void dfs2(int u, boolean[] seen, int[] cc, int ccIdx) {
        if (seen[u]) {
            return;
        }
        seen[u] = true;
        for (int[] v : g2.get(u)) {
            dfs2(v[0], seen, cc, ccIdx);
        }
        cc[u] = ccIdx;
    }

    private static void dfs3(int u, long d, long[] depth, long[] gcd, int[] cc) {
        depth[u] = d;
        for (int[] next : g1.get(u)) {
            final int v = next[0];
            final int c = next[1];
            if (cc[u] != cc[v]) {
                continue;
            }
            if (depth[v] == -1) {
                dfs3(v, d + c, depth, gcd, cc);
            } else {
                gcd[cc[u]] = gcd(gcd[cc[u]], Math.abs(d + c - depth[v]));
            }
        }
    }

    static final class Utils {
        private static class Shuffler {
            private static void shuffle(int[] x) {
                final Random r = new Random();

                for (int i = 0; i <= x.length - 2; i++) {
                    final int j = i + r.nextInt(x.length - i);
                    swap(x, i, j);
                }
            }

            private static void shuffle(long[] x) {
                final Random r = new Random();

                for (int i = 0; i <= x.length - 2; i++) {
                    final int j = i + r.nextInt(x.length - i);
                    swap(x, i, j);
                }
            }

            private static void swap(int[] x, int i, int j) {
                final int t = x[i];
                x[i] = x[j];
                x[j] = t;
            }

            private static void swap(long[] x, int i, int j) {
                final long t = x[i];
                x[i] = x[j];
                x[j] = t;
            }
        }

        public static void shuffleSort(int[] arr) {
            Shuffler.shuffle(arr);
            Arrays.sort(arr);
        }

        public static void shuffleSort(long[] arr) {
            Shuffler.shuffle(arr);
            Arrays.sort(arr);
        }

        private Utils() {}
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        private String next() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    //noinspection CallToPrintStackTrace
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int[] nextIntArray(int n) {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++) { a[i] = nextInt(); }
            return a;
        }

        long[] nextLongArray(int n) {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++) { a[i] = nextLong(); }
            return a;
        }
    }
}