#include <bits/stdc++.h>
using namespace std;
struct node {
  int x, y;
};
int n, m, q, u[500010], v[500010], w[500010], f[500010], g[500010], a[500010],
    T, ans[500010];
vector<node> rd[500010], F[500010];
inline int find(int x) {
  if (x == f[x]) return x;
  return f[x] = find(f[x]);
}
inline int find2(int x) {
  if (a[x] < T) a[x] = T, g[x] = f[x];
  if (g[x] == x) return x;
  return g[x] = find2(g[x]);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &u[i], &v[i], &w[i]),
        rd[w[i]].push_back((node){u[i], v[i]});
  cin >> q;
  for (int i = 1, num, x; i <= q; i++) {
    scanf("%d", &num);
    for (int j = 1; j <= num; j++)
      scanf("%d", &x), F[w[x]].push_back((node){i, x});
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int w = 1; w <= 500000; w++) {
    for (int i = 0; i < F[w].size(); i++) {
      if (i == 0 || F[w][i].x != F[w][i - 1].x) T++;
      int x = u[F[w][i].y], y = v[F[w][i].y];
      int fx = find2(x), fy = find2(y);
      if (fx == fy)
        ans[F[w][i].x] = 1;
      else
        g[fx] = fy;
    }
    for (int i = 0; i < rd[w].size(); i++) {
      int fx = find(rd[w][i].x), fy = find(rd[w][i].y);
      if (fx != fy) f[fx] = fy;
    }
  }
  for (int i = 1; i <= q; i++)
    if (ans[i] == 1)
      printf("NO\n");
    else
      printf("YES\n");
  return 0;
}
