#include <bits/stdc++.h>
using namespace std;
template <typename TP>
inline bool rd(TP& r) {
  r = 0;
  char tmp = getchar();
  while (tmp < '0' || tmp > '9') {
    if (tmp == EOF) return 0;
    tmp = getchar();
  }
  while ('0' <= tmp && tmp <= '9') {
    r = (r << 3) + (r << 1) + tmp - '0';
    tmp = getchar();
  }
  return 1;
}
struct edge {
  int u, v, bl;
  long long w;
  edge(int uu = 0, int vv = 0, long long ww = 0, int belon = 0) {
    u = uu, v = vv, w = ww;
    bl = belon;
  }
  friend bool operator<(edge a, edge b) {
    if (a.w != b.w) return a.w < b.w;
    return a.bl < b.bl;
  }
} e[500100], qe[500100];
int n, m, q;
int ac[500100], sz[500100];
int get(int x) {
  if (ac[x] == x) return x;
  ac[x] = get(ac[x]);
  return ac[x];
}
int ask(int x) {
  if (ac[x] == x) return x;
  return ask(ac[x]);
}
int chg[500100 * 2], tp;
void merge(int a, int b) {
  a = ask(a), b = ask(b);
  if (sz[a] < sz[b]) swap(a, b);
  ac[b] = a;
  chg[++tp] = b;
  sz[a] += sz[b];
}
bool fail[500100];
int main() {
  int mxw = 0;
  rd(n), rd(m);
  int u, v;
  int w;
  for (int i = 1; i <= m; i++) {
    rd(u), rd(v);
    rd(w);
    e[i] = edge(u, v, w);
    mxw = max(mxw, w);
  }
  rd(q);
  int k, tot = 0, a;
  for (int i = 1; i <= q; i++) {
    rd(k);
    for (int j = 1; j <= k; j++) {
      rd(a);
      qe[++tot] = e[a];
      qe[tot].bl = i;
    }
  }
  sort(qe + 1, qe + tot + 1);
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= n; i++) {
    ac[i] = i;
    sz[i] = 1;
  }
  int now = 1, bl, po = 1;
  for (w = 1; w <= mxw; w++) {
    for (; now <= tot;) {
      if (w != qe[now].w) break;
      bl = qe[now].bl;
      for (; now <= tot; now++) {
        if (qe[now].bl != bl || qe[now].w != w) break;
        if (ask(qe[now].u) == ask(qe[now].v))
          fail[qe[now].bl] = 1;
        else
          merge(qe[now].u, qe[now].v);
      }
      while (tp) {
        sz[ac[chg[tp]]] -= sz[chg[tp]];
        ac[chg[tp]] = chg[tp];
        tp--;
      }
    }
    for (; po <= m; po++) {
      if (e[po].w != w) break;
      if (get(e[po].u) != get(e[po].v)) merge(e[po].u, e[po].v);
    }
    tp = 0;
  }
  for (int i = 1; i <= q; i++)
    if (fail[i])
      printf("NO\n");
    else
      printf("YES\n");
  return 0;
}
