#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
struct edge {
  int u, v, w;
};
bool cmp(edge &a, edge &b) { return a.w < b.w; }
struct UnionFind {
  vector<int> pr, rank;
  UnionFind(int n) {
    pr.resize(n);
    for (int i = 0; i < n; ++i) pr[i] = i;
    rank.assign(n, 1);
  }
  int root(int x) { return pr[x] == x ? x : root(pr[x]); }
  bool merge(int x, int y) {
    x = root(x), y = root(y);
    if (x == y) return false;
    if (rank[x] < rank[y]) swap(x, y);
    pr[y] = x;
    rank[x] += rank[y];
    return true;
  }
};
map<int, vector<pair<int, int> > > mp[maxn];
vector<edge> edges;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, q;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    edges.push_back({u - 1, v - 1, w});
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int e;
      cin >> e;
      --e;
      mp[edges[e].w][i].push_back({edges[e].u, edges[e].v});
    }
  }
  sort(edges.begin(), edges.end(), cmp);
  int j = 0;
  UnionFind dsu(n);
  vector<bool> ans(q, true);
  for (int wt = 0; wt <= 500000; ++wt) {
    for (auto &qu : mp[wt]) {
      vector<tuple<int, int, int> > rollback;
      for (auto &e : qu.second) {
        int x = dsu.root(e.first), y = dsu.root(e.second);
        rollback.push_back(tuple<int, int, int>{x, dsu.pr[x], dsu.rank[x]});
        rollback.push_back(tuple<int, int, int>{y, dsu.pr[y], dsu.rank[y]});
        if (!dsu.merge(x, y)) ans[qu.first] = false;
      }
      while (!rollback.empty()) {
        auto change = rollback.back();
        dsu.pr[get<0>(change)] = get<1>(change);
        dsu.rank[get<0>(change)] = get<2>(change);
        rollback.pop_back();
      }
    }
    for (; j < m and edges[j].w == wt; ++j) {
      dsu.merge(edges[j].u, edges[j].v);
    }
  }
  for (int i = 0; i < q; ++i) {
    if (ans[i])
      cout << "YES";
    else
      cout << "NO";
    cout << "\n";
  }
  return 0;
}
