#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v;
  int l;
} e[500050];
int ide[500050];
bool cmpide(int x, int y) { return e[x].l < e[y].l; }
struct cut {
  int id, q;
  bool operator<(const cut &rhs) const {
    if (e[id].l == e[rhs.id].l)
      return q < rhs.q;
    else
      return e[id].l < e[rhs.id].l;
  }
} tr[500050 << 2];
int n, m, top;
bool ans[500050];
struct ss {
  int a, b, c, d;
};
struct binchaji {
  int f[500050];
  int cen[500050];
  ss stk[500050];
  void push(int x, int y) {
    stk[++top] = (ss){x, f[x], y, cen[y]};
    f[x] = y;
  }
  void clear() {
    for (register int i = 1; i <= n; i++) f[i] = i, cen[i] = 1;
  }
  int findroot(int x) {
    if (f[x] == x) return x;
    return findroot(f[x]);
  }
  bool insert(int x) {
    int r1 = findroot(e[x].u), r2 = findroot(e[x].v);
    if (r1 == r2) return 0;
    if (cen[r1] > cen[r2]) {
      push(r2, r1);
      cen[r1] = max(cen[r1], cen[r2] + 1);
    } else {
      push(r1, r2);
      cen[r2] = max(cen[r2], cen[r1] + 1);
    }
    return 1;
  }
  void back() {
    f[stk[top].a] = stk[top].b;
    cen[stk[top].c] = stk[top].d;
    top--;
  }
} bcj;
int main() {
  scanf("%d %d", &n, &m);
  for (register int i = 1; i <= m; i++)
    scanf("%d %d %d", &e[i].u, &e[i].v, &e[i].l);
  for (register int i = 1; i <= m; i++) ide[i] = i;
  sort(ide + 1, ide + m + 1, cmpide);
  int q;
  int cc = 0;
  int k, x;
  scanf("%d", &q);
  for (register int i = 1; i <= q; i++) {
    scanf("%d", &k);
    for (register int j = 1; j <= k; j++)
      scanf("%d", &x), tr[++cc] = (cut){x, i};
  }
  sort(tr + 1, tr + cc + 1);
  memset(ans, 1, sizeof(ans));
  int p = 1;
  top = 0;
  bcj.clear();
  for (register int i = 1; i <= cc; i++) {
    if (e[tr[i].id].l != e[tr[i - 1].id].l)
      while (e[ide[p]].l < e[tr[i].id].l && p <= m) bcj.insert(ide[p]), p++;
    int ep, tot = 0;
    for (register int j = i;
         tr[j].q == tr[i].q && e[tr[j].id].l == e[tr[i].id].l; j++) {
      if (!bcj.insert(tr[j].id))
        ans[tr[i].q] = 0;
      else
        tot++;
      ep = j;
    }
    while (tot) bcj.back(), tot--;
    i = ep;
  }
  for (register int i = 1; i <= q; i++)
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  return 0;
}
