#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
struct E {
  int u, v, w;
  bool operator<(const E& temp) const { return w < temp.w; }
} edge[N];
struct ASK {
  int u, v, w, p;
  bool operator<(const ASK& temp) const {
    return w == temp.w ? p < temp.p : w < temp.w;
  }
} ask[N];
int n, m, q;
int root[N], pa[N];
int find(int x) { return x == root[x] ? x : root[x] = find(root[x]); }
int tot;
int vis[N];
int find2(int x) {
  if (vis[x] != tot) {
    vis[x] = tot;
    pa[x] = root[x];
  }
  return pa[x] == x ? x : pa[x] = find2(pa[x]);
}
int ans[N];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    edge[i] = (E){u, v, w};
  }
  cin >> q;
  int cnt = 0;
  for (int i = 1; i <= q; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      int x;
      scanf("%d", &x);
      cnt++;
      ask[cnt] = (ASK){edge[x].u, edge[x].v, edge[x].w, i};
    }
  }
  sort(edge + 1, edge + 1 + m);
  sort(ask + 1, ask + 1 + cnt);
  for (int i = 1; i <= n; i++) root[i] = i;
  int now = 0;
  int num = n;
  for (int i = 1; i <= m; i++) {
    while (now + 1 <= cnt && ask[now + 1].w == edge[i].w) {
      now++;
      int p = ask[now].p;
      int can = 1;
      tot++;
      while (now <= cnt && ask[now].p == p && ask[now].w == edge[i].w) {
        if (find2(ask[now].u) == find2(ask[now].v))
          can = 0;
        else
          pa[find2(ask[now].u)] = find2(ask[now].v);
        now++;
      }
      now--;
      if (!can) ans[p] = -1;
    }
    if (find(edge[i].u) != find(edge[i].v)) {
      root[find(edge[i].u)] = find(edge[i].v);
      num--;
      if (num == 1) {
        for (int j = now + 1; j <= cnt; j++) ans[ask[j].p] = -1;
        break;
      }
    }
  }
  for (int i = 1; i <= q; i++) puts(ans[i] == -1 ? "NO" : "YES");
  return 0;
}
