#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, m, q;
int w[N], fr[N], to[N];
vector<int> E[N];
vector<pair<int, int> > Q[N];
int par[N], par2[N], pos[N], t;
bool wa[N];
int anc(int p) { return p == par[p] ? p : par[p] = anc(par[p]); }
void join(int p, int q) { par[anc(p)] = anc(q); }
int anc2(int p) {
  if (pos[p] != t) pos[p] = t, par2[p] = par[p];
  return p == par2[p] ? p : par2[p] = anc2(par2[p]);
}
void join2(int p, int q) { par2[anc2(p)] = anc2(q); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v >> w[i];
    E[w[i]].push_back(i);
    fr[i] = u, to[i] = v;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int sz;
    cin >> sz;
    while (sz--) {
      int k;
      cin >> k;
      --k;
      Q[w[k]].push_back(make_pair(i, k));
    }
  }
  for (int i = 1; i <= n; ++i) par[i] = i;
  for (int d = 1; d <= 500000; ++d) {
    sort(Q[d].begin(), Q[d].end());
    for (auto it : Q[d]) anc(fr[it.second]), anc(to[it.second]);
    for (int i = 0; i < Q[d].size();) {
      int query_id = Q[d][i].first;
      ++t;
      while (i < Q[d].size() && Q[d][i].first == query_id) {
        int id = Q[d][i].second;
        if (anc2(fr[id]) != anc2(to[id])) {
          join2(fr[id], to[id]);
        } else
          wa[query_id] = 1;
        ++i;
      }
    }
    ++t;
    for (int j : E[d]) {
      if (anc(fr[j]) != anc(to[j])) join(fr[j], to[j]);
    }
  }
  for (int i = 0; i < q; ++i)
    if (wa[i])
      puts("NO");
    else
      puts("YES");
}
