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
# n, m, length = list(map(int,input().split()))
#
# x, y = 0, 0
#
# arr = []
#
# for i in range(n):
#     arr.append(list(input()))
#     try:
#         x, y = i, arr[i].index("X")
#     except:
#         pass
# def dfs(x, y, length, n, m):
#     mapping = {"U":"D", "D":"U", "R":"L", "L": "R"}
#     stack = []
#     stack.append([x, y])
#     word = ""
#     l = 0
#     while stack:
#
#         now = stack[-1]
#
#         x2, y2 = now
#         if l == length:
#             for char in word[::-1]:
#                 word += mapping[char]
#             return word
#
#         elif n > x2 + 1 >= 0 and arr[x2+1][y2] != "*":
#             stack.append([x2+1, y2])
#             word += "D"
#             l += 1
#
#         elif m > y2 - 1 >= 0 and arr[x2][y2-1] != "*":
#             stack.append([x2, y2-1])
#             word += "L"
#             l += 1
#         elif m > y2 + 1 >= 0 and arr[x2][y2 + 1] != "*":
#             stack.append([x2, y2 + 1])
#             word += "R"
#             l += 1
#         elif n > x2-1 >= 0 and arr[x2-1][y2] != "*":
#             stack.append([x2-1, y2])
#             word += "U"
#             l += 1
#         else:
#             stack.pop()
#             if l != 0:
#                 word += mapping[word[-1]]
#                 l += 1
#     return word
#
#
# if length %2 == 0:
#     word1 = dfs(x, y, length//2, n, m)
#     if word1 != "":
#         print(word1)
#     else:
#         print("IMPOSSIBLE")
# else:
#     print("IMPOSSIBLE")
from collections import defaultdict
import heapq
from operator import itemgetter

# This class represents a undirected graph using adjacency list representation
class Graph:
    def __init__(self, vertices):
        self.V = vertices  # No. of vertices
        self.graph = defaultdict(list)  # default dictionary to store graph

    # function to add an edge to graph
    def addEdge(self, u, v):
        self.graph[u].append(v)

        # A utility function to find the subset of an element i

    def find_parent(self, parent, i):
        if parent[i] == -1:
            return i
        if parent[i] != -1:
            return self.find_parent(parent, parent[i])

            # A utility function to do union of two subsets

    def union(self, parent, x, y):
        x_set = self.find_parent(parent, x)
        y_set = self.find_parent(parent, y)
        parent[x_set] = y_set



        # The main function to check whether a given graph

    # contains cycle or not
    def isCyclic(self):

        # Allocate memory for creating V subsets and
        # Initialize all subsets as single element sets
        parent = [-1] * (self.V)

        # Iterate through all edges of graph, find subset of both
        # vertices of every edge, if both subsets are same, then
        # there is cycle in graph.
        for i in self.graph:
            for j in self.graph[i]:
                x = self.find_parent(parent, i)
                y = self.find_parent(parent, j)
                if x == y:
                    return True
                self.union(parent, x, y)

        return False
                # Create a graph given in the above diagram


n, m = list(map(int, input().split()))
edges = []

for _ in range(m):
     x, y, w = list(map(int, input().split()))
     edges.append([w, x, y])

sortedEdges = sorted(edges,key=itemgetter(0))
q = int(input())

for _ in range(q):


    x, *y = list(map(int, input().split()))
    new_q = []
    for k in y:
        heapq.heappush(new_q, edges[k-1])

    look = set()
    k = 0
    j = 0
    flag = True
    while new_q and flag:

        edge = heapq.heappop(new_q)
        if k == 0 or edge[0] != k:
            k = edge[0]
            for i in edges:
                if i[0] < edge[0]:
                    look.add(i[1])
                    look.add(i[2])
        if edge[1] in look and edge[2] in look:
            flag = False
            break
        look.add(edge[1])
        look.add(edge[2])

    if flag:
        print("YES")
    else:
        print("NO")











