#include <bits/stdc++.h>
using namespace std;
const int MXN = 5e5 + 20;
struct edge {
  int v, u, w;
  edge() { v = u = w = 0; }
  edge(int V, int U, int W) {
    v = V;
    u = U;
    w = W;
  }
  bool operator<(const edge &e) const { return w < e.w; }
};
struct query {
  int w, idx;
  vector<pair<int, int> > ed;
  query(int W = 0, int i = -1) {
    w = W;
    idx = i;
  }
  int size() { return ed.size(); }
  void push_back(int a, int b) { ed.push_back({a, b}); }
  void clear() { ed.clear(); }
  pair<int, int> operator[](int x) { return ed[x]; }
};
int n, m, t;
vector<edge> e;
vector<query> q[MXN];
vector<int> adj[MXN];
bool ans[MXN], mark[MXN];
int par[MXN], sz[MXN];
void dsu_prep() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}
int get_par(int v) { return (par[v] == v ? v : par[v] = get_par(par[v])); }
bool unite(int v, int u) {
  v = get_par(v);
  u = get_par(u);
  if (v == u) return 0;
  if (sz[v] < sz[u]) swap(v, u);
  sz[v] += sz[u];
  par[u] = v;
  return 1;
}
bool DFS(int v, int dad) {
  mark[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int u = adj[v][i];
    if (u == dad) continue;
    if (mark[u]) {
      return 1;
    } else {
      if (DFS(u, v)) return 1;
    }
  }
  return 0;
}
void add_edges(query q) {
  for (int i = 0; i < q.size(); i++) {
    adj[get_par(q[i].first)].push_back(get_par(q[i].second));
    adj[get_par(q[i].second)].push_back(get_par(q[i].first));
  }
  for (int i = 0; i < q.size(); i++) {
    if (mark[get_par(q[i].first)]) continue;
    if (DFS(get_par(q[i].first), -1)) {
      ans[q.idx] = 1;
    }
  }
  for (int i = 0; i < q.size(); i++) {
    adj[get_par(q[i].first)].clear();
    mark[get_par(q[i].first)] = 0;
    adj[get_par(q[i].second)].clear();
    mark[get_par(q[i].second)] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u, w;
    cin >> v >> u >> w;
    e.push_back(edge(v, u, w));
  }
  cin >> t;
  for (int i = 0; i < t; i++) {
    int k;
    cin >> k;
    vector<edge> tmp;
    for (int j = 0; j < k; j++) {
      int x;
      cin >> x;
      tmp.push_back(e[x - 1]);
    }
    sort(tmp.begin(), tmp.end());
    tmp.push_back(edge(-1, -1, -1));
    query qtmp(0, i);
    for (int j = 0; j < k; j++) {
      qtmp.push_back(tmp[j].v, tmp[j].u);
      if (tmp[j].w != tmp[j + 1].w) {
        qtmp.w = tmp[j].w;
        q[tmp[j].w].push_back(qtmp);
        qtmp.clear();
      }
    }
  }
  dsu_prep();
  sort(e.begin(), e.end());
  e.push_back(edge(-1, -1, -1));
  int l = 0;
  for (int i = 0; i < m; i++) {
    if (e[i].w == e[i + 1].w) continue;
    int w = e[i].w;
    for (int j = 0; j < q[w].size(); j++) {
      add_edges(q[w][j]);
    }
    for (int j = l; j <= i; j++) {
      unite(e[j].v, e[j].u);
    }
    l = i + 1;
  }
  for (int i = 0; i < t; i++) {
    if (ans[i])
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
