#include <bits/stdc++.h>
using namespace std;
int n, m, par[500004], pos[500004], q;
bool kt = true;
struct T {
  int u, v, w, id;
};
T t[500004];
bool lf(const T& x, const T& y) { return x.w < y.w; }
vector<int> vec;
int root(int u) {
  if (u == par[u]) return u;
  return par[u] = root(par[u]);
}
void merg(int u, int v) {
  u = root(u);
  v = root(v);
  par[u] = v;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> t[i].u >> t[i].v >> t[i].w;
    t[i].id = i;
  }
  for (int i = 1; i <= n; i++) par[i] = i;
  sort(t + 1, t + m + 1, lf);
  for (int i = 1; i <= m; i++) {
    int j = i;
    for (; t[j].w == t[i].w; j++) {
      t[j].u = root(t[j].u);
      t[j].v = root(t[j].v);
    }
    for (; i < j; i++) {
      merg(t[i].u, t[i].v);
      pos[t[i].id] = i;
    }
    i--;
  }
  cin >> q;
  for (int i = 1; i <= n; i++) par[i] = i;
  while (q--) {
    int k;
    kt = true;
    cin >> k;
    while (k--) {
      int i;
      cin >> i;
      vec.push_back(t[pos[i]].u);
      vec.push_back(t[pos[i]].v);
      if (root(t[pos[i]].u) == root(t[pos[i]].v)) kt = false;
      merg(t[pos[i]].u, t[pos[i]].v);
    }
    for (auto v : vec) par[v] = v;
    vec.clear();
    if (kt == true)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
