#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, w;
};
Edge edge[500100];
int n, e, q, m;
vector<pair<int, vector<int> > > query[500100];
vector<int> ed[500100], ei, pi;
bool cmp(int a, int b) { return edge[a].w < edge[b].w; }
class DSU {
  int a[500100], b[500100], c[500100];
  vector<int> par_roll, rnk_roll;

 public:
  DSU() {
    for (int i = 0; i < 500100; i++) {
      a[i] = -1;
      b[i] = 0;
      c[i] = 1;
      par_roll.clear();
      rnk_roll.clear();
    }
  }
  int find(int u, bool roll = false) {
    if (a[u] != -1) {
      if (roll) return find(a[u], roll);
      return a[u] = find(a[u], roll);
    }
    return u;
  }
  bool unionn(int u, int v, bool roll = false) {
    int x = find(u, roll), y = find(v, roll);
    if (x == y) return false;
    if (b[x] < b[y]) swap(x, y);
    if (roll) par_roll.push_back(y);
    c[x] += c[y];
    a[y] = x;
    if (b[x] == b[y]) {
      b[x]++;
      rnk_roll.push_back(x);
    }
    return true;
  }
  int size(int u) { return c[find(u)]; }
  void rollback() {
    for (int i = 0; i < rnk_roll.size(); i++) b[rnk_roll[i]]--;
    for (int i = 0; i < par_roll.size(); i++) a[par_roll[i]] = -1;
    rnk_roll.clear();
    par_roll.clear();
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> e;
  for (int i = 1; i <= e; i++) {
    cin >> edge[i].u >> edge[i].v >> edge[i].w;
    ed[edge[i].w].push_back(i);
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> m;
    ei.resize(m);
    for (int i = 0; i < m; i++) cin >> ei[i];
    sort(ei.begin(), ei.end(), cmp);
    for (int j = 0, k; j < ei.size();) {
      pi.push_back(ei[j]);
      for (k = j + 1; k < m && edge[ei[k]].w == edge[ei[j]].w; k++)
        pi.push_back(ei[k]);
      query[edge[ei[j]].w].push_back(make_pair(i, pi));
      pi.clear();
      j = k;
    }
    ei.clear();
  }
  bool ans[q + 1];
  for (int i = 1; i <= q; i++) ans[i] = true;
  DSU d;
  for (int i = 1, k; i < 500100; i++) {
    for (int j = 0; j < query[i].size(); j++) {
      k = query[i][j].first;
      for (int p = 0; p < query[i][j].second.size(); p++) {
        int x = edge[query[i][j].second[p]].u,
            y = edge[query[i][j].second[p]].v;
        if (!d.unionn(x, y, true)) {
          ans[k] = false;
          break;
        }
      }
      d.rollback();
    }
    for (int j = 0; j < ed[i].size(); j++)
      d.unionn(edge[ed[i][j]].u, edge[ed[i][j]].v);
  }
  for (int i = 1; i <= q; i++) cout << ((ans[i]) ? "YES\n" : "NO\n");
}
