#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 5;
bool mark[N], h;
long long u[N], v[N], w[N], c[N], par[N], ch[N];
vector<pair<long, long> > vec;
vector<long> vs, vt[N];
pair<long, long> upd[N];
int get(int x) { return par[x] == x ? x : par[x] = get(par[x]); }
void mrg(int a, int b) {
  long long a1 = get(a), a2 = get(b);
  if (a1 != a2) {
    if (ch[a1] < ch[a2]) {
      swap(a1, a2);
    }
    par[a1] = a2;
    ch[a2] += ch[a1];
  }
}
void dfs(long long v, long long pd) {
  mark[v] = true;
  long long ff = 0;
  for (auto x : vt[v]) {
    if (x == pd) ff++;
    if (!mark[x]) {
      dfs(x, v);
    } else if (x != pd || (x == pd && ff > 1)) {
      h = 1;
      return;
    }
  }
}
void make(long long id) {
  vs.push_back(id);
  upd[id].first = get(u[id]);
  upd[id].second = get(v[id]);
  c[u[id]] = get(u[id]);
  c[v[id]] = get(v[id]);
  vt[c[u[id]]].push_back(c[v[id]]);
  vt[c[v[id]]].push_back(c[u[id]]);
  mark[c[u[id]]] = 0, mark[c[u[id]]] = 0;
}
void makee(long long id) {
  vs.push_back(id);
  auto x = upd[id];
  vt[x.first].push_back(x.second);
  vt[x.second].push_back(x.first);
  mark[x.first] = 0, mark[x.second] = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    ch[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    cin >> u[i] >> v[i] >> w[i];
    vec.push_back({w[i], i});
  }
  sort(vec.begin(), vec.end());
  vec.push_back({-1, -1});
  make(vec[0].second);
  for (int i = 1; i <= m; i++) {
    if (vec[i].first == vec[i - 1].first) {
      make(vec[i].second);
    } else {
      for (auto x : vs) {
        if (!mark[c[u[x]]]) {
          dfs(c[u[x]], -1);
        }
        if (!mark[c[v[x]]]) {
          dfs(c[v[x]], -1);
        }
      }
      for (auto x : vs) {
        mrg(u[x], v[x]);
        vt[c[u[x]]].clear();
        vt[c[v[x]]].clear();
      }
      vs.clear();
      if (vec[i].second != -1) make(vec[i].second);
    }
  }
  long long q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long k;
    cin >> k;
    vec.clear(), vs.clear();
    long long kk = k;
    while (kk--) {
      long long f;
      cin >> f;
      vec.push_back({w[f - 1], f - 1});
    }
    sort(vec.begin(), vec.end());
    vec.push_back({-1, -1});
    makee(vec[0].second);
    h = 0;
    for (int i = 1; i <= k; i++) {
      if (vec[i].first == vec[i - 1].first) {
        makee(vec[i].second);
      } else {
        for (auto x : vs) {
          auto U = upd[x];
          if (!mark[U.first]) {
            dfs(U.first, -1);
          }
          if (!mark[U.second]) {
            dfs(U.second, -1);
          }
        }
        for (auto x : vs) {
          auto U = upd[x];
          if (U.first == U.second) h = 1;
          vt[U.first].clear();
          vt[U.second].clear();
        }
        vs.clear();
        if (vec[i].second != -1) makee(vec[i].second);
      }
    }
    cout << (h ? "NO\n" : "YES\n");
  }
}
