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".
    # we should figure out that whether there is a MST contains the edges below, a simple solution is for every query
    # first we  add this edges,and then cotinuing run the MST algo check if the result equals the MST result.
    # the complex is O(m*nlogn), we can't stand it. how can we reduce the time cost.we could consider that how many
    # MST can a set of edgs spanning.if we start this question, we should fist think in which condition there is only
    # one MST.I think if now two weights are same the conclusion is right -- it is true
    # there are serval MST if and only if when we check a new edge, it can not  construct new connection but it's weight
    # equal some edge who is already in the edge set.
    # so the origin problem,
    #   if an edge in the query is also in the origin MST, it is legal,
    #   if there is a cirle, it is illegal,
    #   if there is a edge (a, b), and in the origin MST, the max weight  from a to b is smaller than w_ab, it is illegal, if not, it is legal??
    # no the third if can only check whether an edge can apper in the MST alone, there is a situation in example.every edge can apper in the MST, but they can't apper in the same time.
    # the connection with distinct edge: we enumerate two lonely legal edge, if they apper in two circle that they don't have intersection, then they are legal, becausue the substitute of them can not
    # be the same, but if they have intersection, they may be the same only if their weights are the same.if their weights are not equal, we can determine that if they can exist in some MST independently,
    # they can apper together.now we should only considerd that two edge in same weight.but it is impossible to check every two pair, why I considerd the two pair, the destination is two find some properties.
    # we should considerd every two edge that in same weight, so we can considered them together.now the problem is given some edge in same weight X, can they apper together in a MST. considerding the KRUSKAL
    # algo, we have dealed all the edge who's weight bigger than X, now we have a broken tree, if we add all this edges and there don't have a circle, it shows our operation flow the KRUSKAL,so
    # we can determine that all this edge are legal, if not, illegal, it breaks the algo.so we can deal with all the query offline.

fa = [i for i in range(511111)]
stack = []


def get_ancestor(x):
    if fa[x] != x:
        stack.append((x, fa[x]))
        fa[x] = get_ancestor(fa[x])
    return fa[x]


n, m = map(int, input().split())
u = [[] for i in range(n)]
edge = []
for i in range(m):
    t1, t2, t3 = map(int, input().split())
    u[t1].append(i+1)
    edge.append((i+1, t1, t2, t3))

q = int(input())
w = {}
query = []*q
for i in range(q):
    t = list(map(int, input().split()))
    t0 = t[0]
    t1 = t[1:]
    for j in t1:
        e = edge[j-1]
        if e[3] not in w:
            w[e[3]] = {}
        if i not in w[e[3]]:
            w[e[3]][i] = []
        w[e[3]][i].append(e)

edge.sort(key=lambda x: x[3])
lastw = 0
res = [0] * q
for e in edge:
    if e[3] != lastw:
        lastw = e[3]
        for q in w[e[3]]:
            stack = []
            for j in w[e[3]][q]:
                u = j[1]
                v = j[2]
                fa[u] = get_ancestor(u)
                fa[v] = get_ancestor(v)
                if fa[u] == fa[v]:
                    res[q] = 1
                    break
                else:
                    stack.append((u, fa[u]))
                    fa[fa[u]] = fa[v]
            while stack:
                t = stack.pop()
                fa[t[0]] = t[1]

    u = e[1]
    v = e[2]
    fa[u] = get_ancestor(u)
    fa[v] = get_ancestor(v)
    fa[fa[u]] = fa[v]

for i in res:
    if i:
        print('NO')
    else:
        print('YES')
