#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int mod = 1e9 + 7;
const long long MAX = 5e18;
const long long MIN = -MAX;
const int imax = 2e9 + 100;
const int maxn = 5e5 + 100;
const int maxm = maxn;
const int maxw = maxn;
struct Edge {
  long long u, v, w, idx;
} edges[maxm];
int faltu;
int parent[maxn], rnk[maxn];
int ref_parent[maxn], ref_rank[maxn];
vector<pair<int, vector<int> > > cluster[maxw];
bool seen[maxn];
vector<Edge> es[maxm];
vector<pair<int, int> > pars;
bool compare(int a, int b) { return edges[a].w < edges[b].w; }
int find(int u) {
  if (parent[u] == u) return u;
  return find(parent[u]);
}
int find(int u, int parent[]) {
  if (parent[u] == u) return u;
  return find(parent[u], parent);
}
bool merge(int u, int v, bool x) {
  int u_p = find(u), v_p = find(v);
  if (u_p == v_p) return 0;
  pars.push_back({u_p, v_p});
  if (rnk[u_p] > rnk[v_p])
    parent[v_p] = u_p;
  else if (rnk[v_p] > rnk[u_p])
    parent[u_p] = v_p;
  else {
    parent[u_p] = v_p;
    rnk[v_p]++;
  }
  if (x) {
    ref_parent[u_p] = parent[u_p];
    ref_rank[u_p] = rnk[u_p];
    ref_parent[v_p] = parent[v_p];
    ref_rank[v_p] = rnk[v_p];
  }
  return 1;
}
bool cp(Edge e1, Edge e2) { return e1.w < e2.w; }
int main() {
  time_t t1, t2;
  t1 = clock();
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    ref_parent[i] = i, ref_rank[i] = 1;
    parent[i] = i, rnk[i] = 1;
  }
  for (int i = 0; i < m; i++) {
    int x, y, w;
    cin >> x >> y >> w;
    edges[i] = (Edge){x, y, w, i};
    es[w].push_back(edges[i]);
  }
  int q;
  cin >> q;
  vector<int> Q[q];
  for (int i = 0; i < q; i++) {
    int k;
    cin >> k;
    Q[i].reserve(k);
    for (int j = 0; j < k; j++) {
      cin >> faltu;
      Q[i].push_back(faltu - 1);
    }
    sort(Q[i].begin(), Q[i].end(), compare);
  }
  for (int i = 0; i < q; i++) {
    int edge_weight = -1;
    vector<int> vec;
    for (auto& x : Q[i]) {
      if (edges[x].w != edge_weight) {
        if (edge_weight != -1) cluster[edge_weight].push_back({i, vec});
        edge_weight = edges[x].w;
        vec.clear();
      }
      vec.push_back(x);
    }
    if (!vec.empty()) cluster[edge_weight].push_back({i, vec});
  }
  bool ans[q + 1];
  for (int i = 0; i < q; i++) ans[i] = true;
  for (int w = 1; w < maxw; w++) {
    for (pair<int, vector<int> >& v : cluster[w]) {
      int idx = v.first;
      vector<int> vec = v.second;
      if (seen[idx]) continue;
      for (int& i : vec) {
        int u, v, w;
        Edge e = edges[i];
        tie(u, v, w) = tie(e.u, e.v, e.w);
        if (!merge(u, v, false)) {
          ans[idx] = false;
          seen[idx] = true;
          break;
        }
      }
      for (pair<int, int>& i : pars) {
        tie(parent[find(i.first, ref_parent)],
            parent[find(i.second, ref_parent)]) =
            tie(ref_parent[find(i.first, ref_parent)],
                ref_parent[find(i.second, ref_parent)]);
        tie(rnk[find(i.first, ref_parent)], rnk[find(i.second, ref_parent)]) =
            tie(ref_rank[find(i.first, ref_parent)],
                ref_rank[find(i.second, ref_parent)]);
      }
      pars.clear();
    }
    if (es[w].empty()) continue;
    for (Edge e : es[w]) {
      int u, v, w;
      tie(u, v, w) = tie(e.u, e.v, e.w);
      merge(u, v, true);
    }
  }
  for (int i = 0; i < q; i++) cout << (ans[i] == true ? "YES" : "NO") << endl;
  t2 = clock();
  cerr << "time taken: " << t2 - t1 << endl;
  return 0;
}
