#include <bits/stdc++.h>
using namespace std;
int N, M, notValid[500009] = {};
struct edge {
  int u, v, w, idx;
  edge() {}
  edge(int _u, int _v, int _idx, int _w) { u = _u, v = _v, idx = _idx, w = _w; }
  bool operator<(edge other) const { return w < other.w; }
};
edge edges[500009];
stack<int> res, prevrank, prevf;
vector<int> parent, rk;
class UnionFind {
 public:
  UnionFind(int N) {
    rk.assign(N + 9, 0);
    parent.assign(N + 9, 0);
    for (int i = 0; i < N; i++) parent[i] = i;
  }
  int find(int i) {
    while (i != parent[i]) i = parent[i];
    return i;
  }
  bool isSameSet(int i, int j) { return find(i) == find(j); }
  bool unionSet(int i, int j, bool well) {
    if (isSameSet(i, j)) return false;
    int x = find(i), y = find(j);
    if (well) {
      res.push(x);
      res.push(y);
      prevrank.push(rk[x]);
      prevrank.push(rk[y]);
      prevf.push(parent[x]);
      prevf.push(parent[y]);
    }
    if (rk[x] > rk[y])
      parent[y] = x;
    else {
      parent[x] = y;
      if (rk[x] == rk[y]) rk[y]++;
    }
    return true;
  }
  void reset() {
    while (!res.empty()) {
      int x = res.top();
      rk[x] = prevrank.top();
      parent[x] = prevf.top();
      res.pop();
      prevrank.pop();
      prevf.pop();
    }
  }
};
map<int, set<int> > vals[500009];
int pos[500009];
int main() {
  int a, b, w, q, n;
  scanf("%d%d", &N, &M);
  bool poss = false;
  for (int i = 0; i < M; i++) {
    scanf("%d%d%d", &a, &b, &w);
    edges[i] = edge(a, b, i + 1, w);
  }
  sort(edges, edges + M);
  for (int i = 0; i < M; i++) pos[edges[i].idx] = i;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &n);
    for (int j = 0; j < n; j++) {
      scanf("%d", &a);
      vals[edges[pos[a]].w][i].insert(pos[a]);
    }
  }
  UnionFind UF(N);
  int m = 0;
  for (int i = 1; i < 500009; i++) {
    for (map<int, set<int> >::iterator it = vals[i].begin();
         it != vals[i].end(); it++) {
      int query = (*it).first;
      set<int> &es = (*it).second;
      for (set<int>::iterator jt = es.begin(); jt != es.end(); jt++) {
        int u = edges[*jt].u, v = edges[*jt].v;
        if (!UF.unionSet(u, v, 1)) {
          notValid[query] = 1;
          break;
        }
      }
      UF.reset();
    }
    while (m < M && edges[m].w == i) {
      UF.unionSet(edges[m].u, edges[m].v, 0);
      m++;
    }
  }
  for (int i = 0; i < q; i++) {
    if (notValid[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
}
