#include <bits/stdc++.h>
using namespace std;
struct DJS {
  int sz[500005], p[500005];
  stack<int> s;
  void init(int x) {
    for (int i = 0; i <= x; i++) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  inline int query(int x) { return x == p[x] ? x : query(p[x]); }
  inline void unite(int x, int y) {
    x = query(x), y = query(y);
    if (sz[x] > sz[y]) {
      sz[x] += sz[y];
      p[y] = x;
      s.push(x);
      s.push(y);
    } else {
      sz[y] += sz[x];
      p[x] = y;
      s.push(y);
      s.push(x);
    }
  }
  inline bool same(int x, int y) { return query(x) == query(y); }
  void save() {}
  void undo(int &t) {
    while (t--) {
      int x = s.top();
      s.pop();
      int y = s.top();
      s.pop();
      p[x] = x;
      sz[y] -= sz[x];
    }
    t++;
  }
} djs;
struct Edge {
  int id, from, to, w;
  bool operator<(const Edge &x) const { return w < x.w; }
} E[500005];
bitset<500005> ans;
vector<Edge> Q[500005];
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  djs.init(n);
  for (int i = 1; i <= m; i++) cin >> E[i].from >> E[i].to >> E[i].w;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      E[x].id = i;
      Q[E[x].w].push_back(E[x]);
    }
  }
  sort(E + 1, E + m + 1);
  int pre = 0;
  for (int i = 1; i <= m; i++) {
    if (E[i].w != pre) {
      int preid = -1, time = 0;
      for (Edge j : Q[E[i].w]) {
        if (preid != j.id) djs.undo(time);
        if (djs.same(j.from, j.to))
          ans[j.id] = 1;
        else
          djs.unite(j.from, j.to), time++;
        preid = j.id;
      }
      djs.undo(time);
    }
    if (!djs.same(E[i].from, E[i].to)) {
      djs.unite(E[i].from, E[i].to);
    }
    pre = E[i].w;
  }
  for (int i = 0; i < q; i++) cout << (ans[i] ? "NO" : "YES") << '\n';
  return 0;
}
