#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
int n, m;
struct edge {
  int u, v, w, idx;
};
vector<edge> edges, t_edges;
int test;
struct query {
  int x, sz, idx;
  vector<int> vec;
};
vector<query> queries;
string ans[maxn];
int p[maxn], sz[maxn];
vector<pair<int, int>> G[maxn];
bool mark[maxn];
bool mark_e[maxn];
bool cmp(edge &a, edge &b) { return a.w < b.w; }
bool cmp1(query &a, query &b) { return a.x < b.x; }
int get(int &a) { return p[a] = (p[a] == a ? a : get(p[a])); }
void unite(int a, int b) {
  a = get(a), b = get(b);
  if (a == b) return;
  if (sz[a] < sz[b]) swap(a, b);
  p[b] = a, sz[a] += sz[b];
}
void make_dsu() {
  for (int i = 0; i < n; i++) p[i] = i, sz[i] = 1;
}
bool dfs(int &v) {
  mark[v] = 1;
  bool res = 1;
  for (auto u : G[v]) {
    if (mark_e[u.second]) continue;
    mark_e[u.second] = 1;
    if (mark[u.first]) {
      res = 0;
      continue;
    }
    if (!dfs(u.first)) res = 0;
  }
  return res;
}
void make_graph(vector<int> &vec, int &x) {
  vector<int> cl;
  vector<int> cll;
  int pt = 0;
  for (auto i : vec) {
    int u = get(t_edges[i].u), v = get(t_edges[i].v);
    cl.push_back(u), cl.push_back(v);
    cll.push_back(pt);
    G[u].push_back({v, pt}), G[v].push_back({u, pt++});
  }
  for (int i : cll) mark_e[i] = 0;
  for (int i : cl) {
    if (!mark[i]) {
      if (!dfs(i)) ans[x] = "NO";
    }
  }
  for (int i : cl) {
    G[i].clear();
    mark[i] = 0;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  scanf("%d%d", &n, &m);
  edges.resize(m);
  t_edges.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &edges[i].u, &edges[i].v, &edges[i].w), edges[i].u--,
        edges[i].v--;
    t_edges[i] = edges[i];
  }
  scanf("%d", &test);
  for (int i = 0; i < test; i++) {
    int k;
    scanf("%d", &k);
    vector<pair<int, int>> tmp(k);
    for (int j = 0; j < k; j++)
      scanf("%d", &tmp[j].second), tmp[j].second--,
          tmp[j].first = t_edges[tmp[j].second].w;
    sort(tmp.begin(), tmp.end());
    int cur = tmp[0].first;
    vector<int> help;
    for (auto t : tmp) {
      if (t.first != cur) {
        query tt;
        tt.vec = help, tt.x = cur, tt.sz = help.size(), tt.idx = i;
        queries.push_back(tt);
        cur = t.first;
        help.clear();
      }
      help.push_back(t.second);
    }
    query tt;
    tt.vec = help, tt.x = cur, tt.sz = help.size(), tt.idx = i;
    queries.push_back(tt);
  }
  sort(queries.begin(), queries.end(), cmp1);
  make_dsu();
  sort(edges.begin(), edges.end(), cmp);
  int cur = edges[0].w;
  int pt = 0;
  vector<edge> help;
  for (edge e : edges) {
    if (e.w != cur) {
      while (queries[pt].x == cur) {
        make_graph(queries[pt].vec, queries[pt].idx);
        pt++;
      }
      for (edge temp : help) unite(temp.u, temp.v);
      cur = e.w;
      help.clear();
    }
    help.push_back(e);
  }
  while (queries[pt].x == cur) {
    make_graph(queries[pt].vec, queries[pt].idx);
    pt++;
  }
  for (int i = 0; i < test; i++) {
    if (ans[i] == "NO")
      printf("NO\n");
    else
      printf("YES\n");
  }
}
