#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
vector<pair<pair<int, int>, int>> w[maxn];
int n, m, q, k, par[maxn], e[maxn];
pair<pair<int, int>, int> edge[maxn];
vector<int> adj[maxn];
bool mark[maxn];
pair<int, int> p[maxn];
int get_par(int v) { return v == par[v] ? v : par[v] = get_par(par[v]); }
void merge(int v, int u) {
  int gv = get_par(v), gu = get_par(u);
  if (gv != gu) par[gv] = gu;
  return;
}
bool dfs(int v) {
  ++mark[v];
  bool javab = false;
  int cnt = 0;
  for (auto u : adj[v])
    if (!mark[u])
      javab |= dfs(u);
    else
      ++cnt;
  javab |= (cnt > 1);
  return javab;
}
bool cmp(int e1, int e2) { return edge[e1].second < edge[e2].second; }
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) par[i] = i;
  for (int i = 0; i < m; ++i) {
    int v, u, we;
    cin >> v >> u >> we;
    w[we].push_back({{v - 1, u - 1}, i});
    edge[i] = {{v - 1, u - 1}, we};
  }
  for (int i = 1; i < maxn; ++i)
    if (!w[i].empty()) {
      for (auto j : w[i])
        p[j.second] = {get_par(j.first.first), get_par(j.first.second)};
      for (auto j : w[i]) merge(j.first.first, j.first.second);
    }
  cin >> q;
  while (q--) {
    cin >> k;
    bool f = false;
    for (int i = 0; i < k; ++i) {
      cin >> e[i];
      if (p[--e[i]].first == p[e[i]].second) ++f;
    }
    if (f) {
      cout << "NO" << '\n';
      continue;
    }
    sort(e, e + k, cmp);
    int p1 = 0, p2 = 0;
    while (p2 < k && !f) {
      while (p2 < k && edge[e[p1]].second == edge[e[p2]].second) {
        int v = p[e[p2]].first, u = p[e[p2]].second;
        adj[v].push_back(u);
        adj[u].push_back(v);
        p2++;
      }
      for (int i = p1; i < p2; ++i) {
        int v = p[e[i]].first, u = p[e[i]].second;
        if (!mark[v]) f |= dfs(v);
        if (!mark[u]) f |= dfs(u);
      }
      for (int i = p1; i < p2; ++i) {
        int v = p[e[i]].first, u = p[e[i]].second;
        adj[v].clear();
        adj[u].clear();
        mark[v] = false;
        mark[u] = false;
      }
      p1 = p2;
    }
    if (f)
      cout << "NO" << '\n';
    else
      cout << "YES" << '\n';
  }
  return 0;
}
