#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
inline int read() {
  int x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
struct edge {
  int a, b, w;
} e[500005];
struct opt {
  int pos, f, r;
} st[500005];
int n, m, q, top = 0, cnt = 0;
vector<int> vec[500005];
vector<int> t[500005];
vector<int> d[500005];
int id[500005], bel[500005], vis[500005];
int fa[500005], rk[500005];
bool res[500005];
inline int getf(int a) {
  while (a != fa[a]) a = fa[a];
  return a;
}
int main() {
  int i, j, k, num, maxw = 0;
  n = read();
  m = read();
  for (i = 1; i <= m; i++) {
    e[i].a = read();
    e[i].b = read();
    e[i].w = read();
    d[e[i].w].push_back(i);
    if (e[i].w > maxw) maxw = e[i].w;
  }
  q = read();
  for (i = 1; i <= q; i++) {
    num = read();
    for (j = 1; j <= num; j++) {
      id[j] = read();
      if (!vis[e[id[j]].w]) {
        vis[e[id[j]].w] = ++cnt;
        bel[cnt] = i;
        vec[e[id[j]].w].push_back(cnt);
      }
      t[vis[e[id[j]].w]].push_back(id[j]);
    }
    for (j = 1; j <= num; j++) {
      vis[e[id[j]].w] = 0;
    }
  }
  for (i = 1; i <= n; i++) {
    fa[i] = i;
  }
  for (i = 1; i <= maxw; i++) {
    int sz = vec[i].size();
    for (j = 0; j < sz; j++) {
      int siz = t[vec[i][j]].size(), g = bel[vec[i][j]];
      if (res[g]) {
        continue;
      }
      for (k = top = 0; k < siz; k++) {
        int p = t[vec[i][j]][k];
        int faa = getf(e[p].a), fab = getf(e[p].b);
        if (faa == fab) {
          res[g] = 1;
          break;
        }
        st[++top].pos = faa;
        st[top].f = fa[faa];
        st[top].r = rk[faa];
        st[++top].pos = fab;
        st[top].f = fa[fab];
        st[top].r = rk[fab];
        if (rk[faa] > rk[fab]) {
          fa[fab] = faa;
        } else {
          fa[faa] = fab;
        }
        if (rk[faa] == rk[fab]) rk[fab]++;
      }
      for (k = top; k >= 1; k--) {
        int p = st[k].pos;
        fa[p] = st[k].f;
        rk[p] = st[k].r;
      }
    }
    sz = d[i].size();
    for (j = 0; j < sz; j++) {
      int faa = getf(e[d[i][j]].a), fab = getf(e[d[i][j]].b);
      if (faa == fab) {
        continue;
      }
      if (rk[faa] > rk[fab]) {
        fa[fab] = faa;
      } else {
        fa[faa] = fab;
      }
      if (rk[faa] == rk[fab]) rk[fab]++;
    }
  }
  for (i = 1; i <= q; i++) {
    puts(res[i] ? "NO" : "YES");
  }
  return 0;
}
