#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
const int mod = 1e9 + 7;
struct DSU {
  int pre[maxn], h[maxn], top;
  struct Node {
    int x, y, fa, h;
  } stk[maxn];
  void init(int n) {
    top = 0;
    for (int i = 1; i <= n; ++i) pre[i] = i, h[i] = 0;
  }
  int Find(int x) { return pre[x] == x ? x : Find(pre[x]); }
  void merge(int u, int v) {
    int x = Find(u), y = Find(v);
    if (x == y) return;
    if (h[x] > h[y]) swap(x, y);
    stk[top++] = {x, y, 0, h[y]};
    if (h[x] == h[y]) h[y]++;
    pre[x] = y;
  }
  void revoc(int k) {
    for (int i = 0; i < k; ++i) {
      Node it = stk[--top];
      pre[it.x] = it.x;
      h[it.y] = it.h;
    }
  }
} dsu;
struct EDGE {
  int s, t, cost;
  friend bool operator<(EDGE a, EDGE b) { return a.cost < b.cost; }
} edge[maxn];
struct Query {
  int s, t, qid, cost;
  friend bool operator<(Query a, Query b) {
    return a.cost == b.cost ? a.qid < b.qid : a.cost < b.cost;
  }
} q[maxn];
bool ans[maxn];
int main() {
  memset(ans, 1, sizeof(ans));
  int n, m, p;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &edge[i].s, &edge[i].t, &edge[i].cost);
  }
  scanf("%d", &p);
  int tot = 0;
  for (int i = 1, a, b; i <= p; ++i) {
    scanf("%d", &a);
    for (int j = 1; j <= a; ++j) {
      scanf("%d", &b);
      q[++tot] = {edge[b].s, edge[b].t, i, edge[b].cost};
    }
  }
  sort(edge + 1, edge + 1 + m);
  sort(q + 1, q + 1 + tot);
  dsu.init(n);
  int now = 1;
  for (int i = 1; i <= m; ++i) {
    int cnt = 0;
    while (q[now].cost == edge[i].cost) {
      if (q[now - 1].cost == q[now].cost && q[now].qid != q[now - 1].qid)
        dsu.revoc(cnt), cnt = 0;
      int x = dsu.Find(q[now].s), y = dsu.Find(q[now].t);
      if (x == y) {
        ans[q[now].qid] = 0;
      } else
        dsu.merge(x, y), cnt++;
      now++;
    }
    dsu.revoc(cnt);
    dsu.merge(edge[i].s, edge[i].t);
  }
  for (int i = 1; i <= p; ++i) {
    if (ans[i])
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
