#include <bits/stdc++.h>
using namespace std;
const int MN = 500010;
int N, M, Q;
struct Edge {
  int u, v, w;
  bool operator<(const Edge &i) const { return w < i.w; }
};
Edge edge[MN];
struct Query {
  vector<Edge> edge;
  int id;
};
vector<Query> query[MN];
int ans[MN];
struct DSU {
  int n;
  int fa[MN];
  void init(int n_) {
    n = n_;
    for (int i = 0; i < n; i++) fa[i] = i;
  }
  int find(int u) {
    if (fa[u] == u)
      return u;
    else
      return fa[u] = find(fa[u]);
  }
  void mrg(int u, int v) {
    u = find(u);
    v = find(v);
    fa[v] = u;
  }
} dsu1, dsu2;
int Xn;
vector<int> X;
map<int, int> dx;
vector<vector<int> > adj;
vector<int> vis;
bool dfs(int u, int p) {
  vis[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    if (vis[v]) return true;
    if (dfs(v, u)) return true;
  }
  return false;
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int u, v, w;
    scanf("%d %d %d", &u, &v, &w);
    u--;
    v--;
    edge[i] = {u, v, w};
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int k;
    scanf("%d", &k);
    vector<Edge> tmp;
    for (int j = 0; j < k; j++) {
      int t;
      scanf("%d", &t);
      t--;
      tmp.push_back(edge[t]);
    }
    sort(tmp.begin(), tmp.end());
    int st = 0;
    for (int j = 0; j < k; j++) {
      if (j == k - 1 || tmp[j].w != tmp[j + 1].w) {
        Query x;
        for (int a = st; a <= j; a++) {
          x.edge.push_back(tmp[a]);
        }
        x.id = i;
        query[tmp[j].w].push_back(x);
        st = j + 1;
      }
    }
  }
  sort(edge, edge + M);
  int pos = 0;
  dsu1.init(N);
  for (int q = 0; q < MN; q++) {
    for (int i = 0; i < query[q].size(); i++) {
      Query x = query[q][i];
      X.clear();
      dx.clear();
      for (int j = 0; j < x.edge.size(); j++) {
        int u = dsu1.find(x.edge[j].u);
        int v = dsu1.find(x.edge[j].v);
        X.push_back(u);
        X.push_back(v);
      }
      sort(X.begin(), X.end());
      X.resize(unique(X.begin(), X.end()) - X.begin());
      Xn = X.size();
      for (int j = 0; j < Xn; j++) dx[X[j]] = j;
      dsu2.init(Xn);
      for (int j = 0; j < x.edge.size(); j++) {
        int u = dx[dsu1.find(x.edge[j].u)];
        int v = dx[dsu1.find(x.edge[j].v)];
        if (dsu2.find(u) == dsu2.find(v)) {
          ans[x.id] = 1;
          break;
        }
        dsu2.mrg(u, v);
      }
    }
    while (pos < M && edge[pos].w == q) {
      dsu1.mrg(edge[pos].u, edge[pos].v);
      pos++;
    }
  }
  for (int i = 0; i < Q; i++) {
    if (ans[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
}
