#include <bits/stdc++.h>
using namespace std;
struct eInfo {
  long long u, v, w;
  void inp() {
    scanf("%lld", &u);
    scanf("%lld", &v);
    scanf("%lld", &w);
  }
  bool operator<(const eInfo &arg) const { return w < arg.w; }
} e[500010];
struct qInfo {
  long long id, w, u, v;
  void inp(long long qNo) {
    id = qNo;
    long long i;
    scanf("%lld", &i);
    w = e[i].w;
    u = e[i].u;
    v = e[i].v;
  }
  bool operator<(const qInfo &arg) const {
    if (w == arg.w) {
      return id < arg.id;
    } else
      return w < arg.w;
  }
} q[500010];
long long rnk[500010], par[500010];
void init() {
  for (long long i = 0; i < 500010; i++) {
    rnk[i] = 0;
    par[i] = i;
  }
}
long long fnd(long long u) {
  if (u == par[u])
    return u;
  else
    return fnd(par[u]);
}
struct saveInfo {
  long long u, urnk, v, vrnk;
};
stack<saveInfo> states;
long long uni(long long u, long long v) {
  long long p_u = fnd(u);
  long long p_v = fnd(v);
  saveInfo tmp;
  tmp.u = p_u;
  tmp.urnk = rnk[p_u];
  tmp.v = p_v;
  tmp.vrnk = rnk[p_v];
  states.push(tmp);
  if (p_u == p_v) return false;
  if (rnk[p_u] < rnk[p_v])
    par[p_u] = p_v;
  else if (rnk[p_u] > rnk[p_v])
    par[p_v] = p_u;
  else {
    par[p_u] = p_v;
    rnk[p_v]++;
  }
  return true;
}
long long ans[500010];
int main() {
  for (long long i = 0; i < 500010; i++) ans[i] = true;
  long long n, m;
  scanf("%lld", &n);
  scanf("%lld", &m);
  for (long long i = 1; i <= m; i++) e[i].inp();
  long long qsz;
  scanf("%lld", &qsz);
  long long iq = 1;
  for (long long h = 1; h <= qsz; h++) {
    long long k;
    scanf("%lld", &k);
    while (k--) {
      q[iq].inp(h);
      iq++;
    }
  }
  sort(e + 1, e + 1 + m);
  sort(q + 1, q + iq);
  init();
  long long ptr = 1;
  iq--;
  long long cnt = 0;
  for (long long i = 1; i <= iq; i++) {
    while (e[ptr].w < q[i].w && ptr <= m) {
      uni(e[ptr].u, e[ptr].v);
      ptr++;
    }
    if (q[i].w != q[i - 1].w) cnt = 0;
    if (fnd(q[i].u) == fnd(q[i].v)) {
      ans[q[i].id] = false;
    } else {
      uni(q[i].u, q[i].v);
      cnt++;
    }
    if (q[i].id != q[i + 1].id && q[i].w == q[i + 1].w) {
      while (cnt) {
        saveInfo tmp = states.top();
        states.pop();
        par[tmp.u] = tmp.u;
        par[tmp.v] = tmp.v;
        rnk[tmp.u] = tmp.urnk;
        rnk[tmp.v] = tmp.vrnk;
        cnt--;
      }
    }
  }
  for (long long i = 1; i <= qsz; i++) {
    if (ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
