#include <bits/stdc++.h>
using namespace std;
const int N = 501000;
int n, m, u[N], v[N], w[N], f[N], p[N], qrcase[N], T, wa[N];
int Q, k, id, x, maxw;
vector<int> eg[N];
vector<pair<int, int> > qw[N];
int nxt1[N], nxt2[N];
int find1(int now) {
  if (nxt1[now] == now) return now;
  return nxt1[now] = find1(nxt1[now]);
}
int find2(int now) {
  if (qrcase[now] != T) {
    qrcase[now] = T;
    nxt2[now] = nxt1[now];
  }
  if (nxt2[now] == now) return now;
  return nxt2[now] = find2(nxt2[now]);
}
int main() {
  maxw = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    eg[w[i]].push_back(i);
    maxw = max(maxw, w[i]);
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d", &id);
    for (int j = 0; j < id; j++) {
      scanf("%d", &x);
      qw[w[x]].push_back(make_pair(i, x));
    }
  }
  memset(wa, 0, sizeof(wa));
  for (int i = 1; i <= n; i++) {
    nxt1[i] = i;
  }
  T = 0;
  for (int i = 1; i <= maxw; i++) {
    sort(qw[i].begin(), qw[i].end());
    for (int j = 0; j < qw[i].size(); j++) {
      if (j == 0 || qw[i][j].first != qw[i][j - 1].first) T++;
      int x = u[qw[i][j].second], y = v[qw[i][j].second];
      if (find2(x) == find2(y)) {
        wa[qw[i][j].first] = true;
      }
      nxt2[find2(y)] = nxt2[find2(x)];
    }
    for (int j = 0; j < eg[i].size(); j++) {
      int x = find1(u[eg[i][j]]);
      int y = find1(v[eg[i][j]]);
      nxt1[find1(y)] = find1(x);
    }
  }
  for (int i = 0; i < Q; i++) {
    if (wa[i])
      printf("NO\n");
    else
      printf("YES\n");
  }
}
