#include <bits/stdc++.h>
using namespace std;
struct edg {
  int x;
  int y;
  int v;
  int bel;
  friend bool operator<(const edg &x, const edg &y) {
    return x.v != y.v ? x.v < y.v : x.bel < y.bel;
  }
};
int f[500010], h[500010];
edg e[500010], a[500010];
int tot;
bool unable[500010];
int st[500010], tp;
int n, m, q;
int fa(int x) { return f[x] == x ? x : fa(f[x]); }
bool cot(int x, int y) {
  int fx = fa(x), fy = fa(y);
  if (fx == fy) {
    return 0;
  }
  if (h[fx] <= h[fy]) {
    swap(fx, fy);
  }
  f[fy] = fx;
  st[++tp] = fy;
  if (h[fx] == h[fy]) {
    h[fx]++;
    st[tp] *= -1;
  }
  return 1;
}
void roolback(int tim) {
  while (tp != tim) {
    int x = st[tp];
    if (x < 0) {
      x = -x;
      h[f[x]]--;
    }
    f[x] = x;
    tp--;
  }
}
int main() {
  int i, j, k, x, y;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    f[i] = i;
  }
  for (i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].v);
  }
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    scanf("%d", &x);
    while (x--) {
      scanf("%d", &y);
      a[++tot] = e[y];
      a[tot].bel = i;
    }
  }
  sort(e + 1, e + m + 1);
  sort(a + 1, a + tot + 1);
  int wzh = 1;
  int now;
  for (i = 1; i <= m; i++) {
    for (j = wzh; j <= tot && a[j].v == e[i].v; j++) {
      now = tp;
      for (k = j; k <= tot && a[k].v == a[j].v && a[k].bel == a[j].bel; k++) {
        if (!cot(a[k].x, a[k].y)) {
          unable[a[j].bel] = 1;
        }
      }
      j = k - 1;
      roolback(now);
    }
    wzh = j;
    for (j = i; j <= m && e[j].v == e[i].v; j++) {
      cot(e[j].x, e[j].y);
    }
    i = j - 1;
  }
  for (i = 1; i <= q; i++) {
    printf(unable[i] ? "NO\n" : "YES\n");
  }
  return 0;
}
