#include <bits/stdc++.h>
using namespace std;
const int kN = 500010;
const int kM = 500010;
const int kW = 500010;
const int kQ = 500010;
int N, M, Q;
int U[kM], V[kM], W[kM];
vector<int> wv;
vector<pair<int, int> > ev[kW], qv[kW];
bool res[kQ];
int dsi[kN];
int find_set(int x) { return dsi[x] == -1 ? x : (dsi[x] = find_set(dsi[x])); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> N >> M;
  for (int mi = 1; mi <= M; ++mi) {
    cin >> U[mi] >> V[mi] >> W[mi];
    ev[W[mi]].push_back(make_pair(U[mi], V[mi]));
    wv.push_back(W[mi]);
  }
  cin >> Q;
  for (int qi = 0; qi < Q; ++qi) {
    int K, e;
    cin >> K;
    for (int ki = 0; ki < K; ++ki) {
      cin >> e;
      qv[W[e]].push_back(make_pair(qi, e));
    }
  }
  sort(wv.begin(), wv.end());
  wv.erase(unique(wv.begin(), wv.end()), wv.end());
  fill(dsi, dsi + (N + 1), -1);
  fill(res, res + Q, true);
  for (int w : wv) {
    vector<pair<int, int> > &rqv = qv[w];
    sort(rqv.begin(), rqv.end());
    for (int i = 0, j, q; i < int(rqv.size()); i = j) {
      j = i + 1, q = rqv[i].first;
      while (j < int(rqv.size()) && rqv[j].first == q) ++j;
      set<int> head_set;
      vector<pair<int, int> > union_ops;
      for (int k = i; k < j; ++k) {
        int e = rqv[k].second;
        int u = find_set(U[e]), v = find_set(V[e]);
        head_set.insert(u), head_set.insert(v);
        union_ops.push_back(make_pair(u, v));
      }
      for (auto uo : union_ops) {
        int u = find_set(uo.first), v = find_set(uo.second);
        if (u == v) res[q] = false;
        if (u != v) dsi[v] = u;
      }
      for (int head : head_set) dsi[head] = -1;
    }
    vector<pair<int, int> > &rev = ev[w];
    for (int i = 0; i < int(rev.size()); ++i) {
      int u = find_set(rev[i].first), v = find_set(rev[i].second);
      if (u != v) dsi[v] = u;
    }
  }
  for (int qi = 0; qi < Q; ++qi) cout << (res[qi] ? "YES" : "NO") << "\n";
  return 0;
}
