For a connected undirected weighted graph *G*, MST (minimum spanning tree) is a subgraph of *G* that contains all of *G*'s vertices, is a tree, and sum of its edges is minimum possible.

You are given a graph *G*. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You are given some queries, each query contains a set of edges of graph *G*, and you should determine whether there is a MST containing all these edges or not.
The first line contains two integers *n*, *m* (2  ≤ *n*, *m*  ≤ 5·10<sup class="upper-index">5</sup>, *n* - 1 ≤ *m*) — the number of vertices and edges in the graph and the number of queries.

The *i*-th of the next *m* lines contains three integers *u*<sub class="lower-index">*i*</sub>, *v*<sub class="lower-index">*i*</sub>, *w*<sub class="lower-index">*i*</sub> (*u*<sub class="lower-index">*i*</sub> ≠ *v*<sub class="lower-index">*i*</sub>, 1 ≤ *w*<sub class="lower-index">*i*</sub> ≤ 5·10<sup class="upper-index">5</sup>) — the endpoints and weight of the *i*-th edge. There can be more than one edges between two vertices. It's guaranteed that the given graph is connected.

The next line contains a single integer *q* (1 ≤ *q* ≤ 5·10<sup class="upper-index">5</sup>) — the number of queries.

*q* lines follow, the *i*-th of them contains the *i*-th query. It starts with an integer *k*<sub class="lower-index">*i*</sub> (1 ≤ *k*<sub class="lower-index">*i*</sub> ≤ *n* - 1) — the size of edges subset and continues with *k*<sub class="lower-index">*i*</sub> distinct space-separated integers from 1 to *m* — the indices of the edges. It is guaranteed that the sum of *k*<sub class="lower-index">*i*</sub> for 1 ≤ *i* ≤ *q* does not exceed 5·10<sup class="upper-index">5</sup>.
This is the graph of sample:

Weight of minimum spanning tree on this graph is 6.

MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".

Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer is "NO".
5 7
1 2 2
1 3 2
2 3 1
2 4 1
3 4 1
3 5 2
4 5 2
4
2 3 4
3 3 4 5
2 1 7
2 1 2
YES
NO
YES
NO
5 8
2 1 4
3 1 4
4 1 5
5 2 3
4 5 2
4 5 4
1 4 4
3 4 2
10
1 1
3 4 1 5
1 2
3 4 1 3
2 4 3
3 2 5 4
2 2 4
4 3 2 1 4
1 3
2 2 1
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
12 29
2 1 1
3 1 2
4 1 5
5 1 3
6 3 5
7 3 3
8 7 4
9 4 2
10 2 4
11 1 4
12 2 5
5 9 2
6 9 3
12 5 1
2 10 1
10 11 5
5 7 4
2 12 5
10 11 3
5 9 3
2 12 2
11 12 1
1 6 4
2 10 4
12 7 1
6 12 4
7 10 1
4 7 3
12 4 5
10
10 12 6 3 8 7 5 11 10 9 1
9 12 9 10 7 4 6 1 8 3
2 5 3
7 7 11 10 12 6 5 9
9 3 8 10 2 9 12 6 11 7
2 6 2
8 4 1 7 10 12 2 9 11
10 5 9 3 1 4 7 6 2 10 8
9 10 8 6 11 1 4 7 3 2
3 7 6 11
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
14 16
2 1 3
3 1 5
4 3 4
5 3 5
6 3 5
7 2 1
8 6 5
9 2 5
10 2 2
11 1 4
12 5 2
13 12 4
14 12 4
8 11 2
13 14 2
12 14 5
10
12 3 12 6 1 13 8 4 9 5 10 11 14
6 3 7 10 12 11 2
1 8
5 14 13 11 4 1
3 9 4 2
11 1 2 11 8 7 5 9 12 13 4 10
13 7 10 5 6 4 9 12 1 3 8 14 11 13
3 3 9 12
10 13 1 14 11 9 10 6 12 8 3
4 8 11 4 1
NO
YES
YES
YES
YES
NO
NO
YES
NO
YES
5 9
2 1 2
3 1 3
4 2 4
5 3 3
4 5 5
4 5 1
1 3 3
1 5 1
5 4 3
10
4 4 5 3 2
3 4 5 1
3 1 3 4
1 1
4 1 4 5 2
4 2 3 1 5
3 2 3 4
3 5 2 1
4 5 1 4 2
3 3 2 5
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
20 24
2 1 3
3 1 5
4 1 5
5 1 13
6 2 7
7 4 7
8 6 7
9 8 12
10 4 11
11 5 12
12 10 12
13 2 11
14 12 8
15 7 1
16 10 7
17 4 4
18 13 9
19 2 11
20 10 10
16 19 2
1 5 14
19 20 17
3 7 11
15 17 11
20
3 16 9 20
3 24 9 12
1 5
2 9 12
3 1 6 11
3 2 5 21
4 13 17 7 3
3 21 11 20
4 3 19 12 18
2 22 17
1 12
3 1 24 13
4 14 11 5 21
4 5 7 13 11
3 1 7 22
1 12
4 9 15 22 24
3 19 15 21
4 18 8 7 20
4 17 11 3 19
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
YES
YES
16 29
2 1 1
3 2 5
4 2 1
5 3 7
6 1 2
7 4 6
8 4 4
9 3 10
10 8 3
11 8 8
12 2 7
13 2 6
14 11 1
15 4 2
16 3 4
14 16 8
9 15 5
3 6 6
11 15 10
11 15 6
11 13 8
2 6 8
11 13 1
13 15 10
13 15 10
10 13 7
1 9 9
10 13 8
1 15 2
20
2 26 6
2 18 10
1 1
4 12 13 21 28
1 28
4 10 27 26 16
3 10 1 9
3 17 10 16
1 23
2 14 6
4 25 24 6 3
2 3 23
3 24 22 8
1 7
1 29
3 20 28 1
4 10 5 11 17
3 1 8 22
1 15
1 4
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
YES
YES
2 2
1 2 1
1 2 2
2
1 1
1 2
YES
NO
3 2
1 2 3
2 3 6
3
1 1
1 2
2 1 2
YES
YES
YES
class Graph:

    def __init__(self, v):
        self.v = v
        self.edges = {}

    def add_edge(self, v, u, w):
        t = self.edges.get(w)
        if t is None:
            self.edges[w] = {(u, v)}
        else:
            self.edges[w].add((u, v))


def find(j, c):
    while c[j] >= 0:
        j = c[j]
    return j


def merge_components(p1, p2, cc):
    new_weight = (abs(cc[p1]) + abs(cc[p2]))
    if abs(cc[p1]) > abs(cc[p2]):
        cc[p1] = -new_weight
        cc[p2] = p1
    else:
        cc[p2] = -new_weight
        cc[p1] = p2


def undo(c, changes: list):
    j = len(changes) - 1
    while j >= 0:
        idx, v = changes[j]
        c[idx] = v
        j -= 1


def kruskal_weight(w, graph: Graph, cc):
    w_edges = graph.edges.get(w)
    if w_edges:
        for edge in w_edges:
            p1 = find(edge[0], cc)
            p2 = find(edge[1], cc)
            if not p1 == p2:
                merge_components(p1, p2, cc)


def kruskal_next_edge(obligated, c: list):
    changes = []
    if obligated:
        for edge in obligated:
            p1 = find(edge[0], c)
            p2 = find(edge[1], c)
            if p1 == p2:
                undo(c, changes)
                return False
            changes.append((p1, c[p1]))
            changes.append((p2, c[p2]))
            merge_components(p1, p2, c)
    undo(c, changes)
    return True


if __name__ == '__main__':
    edges = []
    n, m = list(map(int, input().split()))
    g = Graph(v=n)
    for _ in range(m):
        a, b, weight = list(map(int, input().split()))
        g.add_edge(a - 1, b - 1, weight)
        edges.append([a - 1, b - 1, weight])
    q = int(input())
    ws = list(g.edges.keys())
    ws.sort()
    questions = []
    weighted_questions = {k: set() for k in ws}
    for _ in range(q):
        temp = list(map(lambda x: int(x) - 1, input().split()))
        ed = {"r": True}
        for que in temp[1:]:
            e = edges[que]
            x = ed.get(e[2])
            weighted_questions[e[2]].add(_)
            if x is None:
                ed[e[2]] = {(e[0], e[1])}
            else:
                ed[e[2]].add((e[0], e[1]))
        questions.append(ed)
    cc = [-1 for _ in range(g.v)]
    for w in ws:
        for i in weighted_questions.get(w):
            q = questions[i]
            wq = q.get(w)
            if wq:
                q["r"] = q["r"] and kruskal_next_edge(wq, cc)
        kruskal_weight(w, g, cc)
    for i in questions:
        print("YES" if i["r"] else "NO")
