#include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1000 + 20;
long long int a[N], m[N], x[N], y[N], w[N], par2[N], par[N], ans[N], vis[N],
    num, rnk[N];
vector<pair<int, int> > e[N], q[N];
int find_root(int u) {
  if (u == par[u]) {
    return u;
  }
  return par[u] = find_root(par[u]);
}
int find_par(int u) {
  if (vis[u] != num) {
    vis[u] = num;
    par2[u] = par[u];
  }
  if (u == par2[u]) {
    return u;
  }
  return par2[u] = find_par(par2[u]);
}
void _merge(int a, int b) {
  int r_a = find_root(a);
  int r_b = find_root(b);
  if (rnk[r_a] > rnk[r_b]) {
    swap(r_a, r_b);
  }
  par[r_a] = r_b;
  if (rnk[r_a] == rnk[r_b]) {
    rnk[r_b]++;
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> x[i] >> y[i] >> w[i];
    e[w[i]].push_back({x[i], y[i]});
  }
  int tt;
  cin >> tt;
  for (int i = 0; i < tt; i++) {
    int a, b;
    cin >> a;
    while (a--) {
      cin >> b;
      q[w[b]].push_back({i, b});
    }
  }
  for (int i = 1; i < N; i++) {
    int last = -1;
    for (auto qu : q[i]) {
      if (last != qu.first) {
        num++;
        last = qu.first;
      }
      int a = find_par(x[qu.second]);
      int b = find_par(y[qu.second]);
      if (a == b) {
        ans[last] = 1;
      } else {
        par2[a] = b;
      }
    }
    for (auto qu : e[i]) {
      _merge(qu.first, qu.second);
    }
  }
  for (int i = 0; i < tt; i++) {
    if (ans[i]) {
      cout << "NO\n";
    } else {
      cout << "YES\n";
    }
  }
}
