#include <bits/stdc++.h>
using namespace std;
struct edge {
  int u, v, w, id;
} e[500001];
int f[500001], last[500001];
int Left[500001];
struct que {
  int x, y, next;
} q[1000001];
int head[500001];
int cnt;
void init() {
  cnt = 0;
  memset(head, -1, sizeof(head));
}
void add_edge(int w, int i, int id) {
  q[cnt].x = i;
  q[cnt].y = id;
  q[cnt].next = head[w];
  head[w] = cnt++;
}
int fa[500001];
int stid[500001 << 3], stfa[500001 << 3], top = 0;
bool cmp(edge a, edge b) {
  if (a.w == b.w) return a.id < b.id;
  return a.w < b.w;
}
int Find(int u) {
  if (u == fa[u]) {
    return u;
  } else {
    int v = Find(fa[u]);
    ++top;
    stid[top] = u, stfa[top] = fa[u];
    fa[u] = v;
    return v;
  }
}
bool add(int id) {
  int u = e[id].u, v = e[id].v;
  u = Find(u), v = Find(v);
  if (u == v) return false;
  ++top;
  stid[top] = u, stfa[top] = fa[u];
  fa[u] = v;
  return true;
}
void back(int ret) {
  while (top > ret) {
    fa[stid[top]] = stfa[top];
    top--;
  }
}
int main() {
  init();
  int n, m, Q;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    e[i].id = i;
  }
  sort(e + 1, e + 1 + m, cmp);
  for (int i = 1; i <= m; i++) f[e[i].id] = i;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int qn;
    scanf("%d", &qn);
    for (int j = 1; j <= qn; j++) {
      int id;
      scanf("%d", &id);
      id = f[id];
      if (last[e[id].w] != i) {
        last[e[id].w] = i;
        Left[i]++;
      }
      add_edge(e[id].w, i, id);
    }
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    if (e[i].w != e[i - 1].w) {
      int w = e[i].w;
      int rec = top;
      for (int j = head[w]; ~j; j = q[j].next) {
        bool ok = true;
        while (q[j].next != -1 && q[j].x == q[q[j].next].x) {
          ok &= add(q[j].y);
          j = q[j].next;
        }
        ok &= add(q[j].y);
        if (ok) {
          Left[q[j].x]--;
        }
        back(rec);
      }
    }
    for (; e[i].w == e[i + 1].w; i++) {
      add(i);
    }
    add(i);
  }
  for (int i = 1; i <= Q; i++) {
    if (!Left[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
}
