#include <bits/stdc++.h>
using namespace std;
struct UF {
  vector<int> parent;
  vector<int> rank;
  UF(int n) {
    parent.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      rank[i] = 0;
    }
  }
  int get(int x) {
    if (parent[x] != x) parent[x] = get(parent[x]);
    return parent[x];
  }
  bool unio(int a, int b) {
    a = get(a);
    b = get(b);
    if (a == b) return false;
    if (rank[a] < rank[b])
      parent[a] = b;
    else
      parent[b] = a;
    if (rank[a] == rank[b]) rank[a]++;
    return true;
  }
};
template <typename T>
bool cycle(UF &uf, T begin, T end, const vector<array<int, 3>> &edges) {
  vector<int> nodes;
  for (T it = begin; it != end; it++) {
    auto &E = edges[(*it)[2]];
    int v1 = uf.get(E[1]);
    int v2 = uf.get(E[2]);
    if (v1 == v2) return true;
    nodes.push_back(v1);
    nodes.push_back(v2);
  }
  sort(nodes.begin(), nodes.end());
  nodes.erase(unique(nodes.begin(), nodes.end()), nodes.end());
  UF curUF(nodes.size());
  for (T it = begin; it != end; it++) {
    auto &E = edges[(*it)[2]];
    int v1 = uf.get(E[1]);
    int v2 = uf.get(E[2]);
    v1 = lower_bound(nodes.begin(), nodes.end(), v1) - nodes.begin();
    v2 = lower_bound(nodes.begin(), nodes.end(), v2) - nodes.begin();
    if (!curUF.unio(v1, v2)) return true;
  }
  return false;
}
int main() {
  int N, M;
  scanf("%d %d", &N, &M);
  vector<array<int, 3>> edges;
  for (int i = 0; i < M; i++) {
    int a, b, w;
    scanf("%d %d %d", &a, &b, &w);
    edges.push_back({w, a - 1, b - 1});
  }
  auto sorted_edges = edges;
  sort(sorted_edges.begin(), sorted_edges.end());
  int q;
  scanf("%d", &q);
  vector<bool> ans(q, true);
  vector<array<int, 3>> queries;
  for (int i = 0; i < q; i++) {
    int k;
    scanf("%d", &k);
    while (k--) {
      int x;
      scanf("%d", &x);
      queries.push_back({edges[x - 1][0], i, x - 1});
    }
  }
  sort(queries.begin(), queries.end());
  int curQ = 0;
  UF uf(N);
  for (auto &edge : sorted_edges) {
    while (curQ < queries.size() && queries[curQ][0] <= edge[0]) {
      int endQ = curQ;
      while (endQ < queries.size() && queries[curQ][0] == queries[endQ][0] &&
             queries[curQ][1] == queries[endQ][1])
        endQ++;
      if (cycle(uf, queries.data() + curQ, queries.data() + endQ, edges))
        ans[queries[curQ][1]] = false;
      curQ = endQ;
    }
    uf.unio(edge[1], edge[2]);
  }
  for (bool b : ans) printf("%s\n", b ? "YES" : "NO");
  return 0;
}
