#include <bits/stdc++.h>
const int MAXN = 5e5 + 5;
int n, m, _q;
struct Node {
  int i, from, to;
  Node(int i = 0, int from = 0, int to = 0) : i(i), from(from), to(to) {}
};
std::vector<Node> a[MAXN];
std::vector<int> q[MAXN];
std::vector<std::pair<int, int> > S[MAXN];
int _[MAXN], u[MAXN], v[MAXN];
int f[MAXN], sz[MAXN];
int ans[MAXN];
inline int find(int x) { return x == f[x] ? x : find(f[x]); }
std::stack<std::pair<int, int> > opt;
inline void Union(int x, int y) {
  int fx = find(x), fy = find(y);
  if (fx == fy) return;
  if (sz[fx] < sz[fy]) std::swap(x, y), std::swap(fx, fy);
  opt.push(std::make_pair(fy, fx));
  f[fy] = fx;
  sz[fx] += sz[fy];
}
inline bool cmp(int x, int y) { return _[x] < _[y]; }
inline void remove() {
  std::pair<int, int> t = opt.top();
  opt.pop();
  f[t.first] = t.first;
  sz[t.second] -= sz[t.first];
}
inline bool chk(int id, int l, int r) {
  bool ans = 1;
  int cnt = 0;
  for (int i = l; i <= r; ++i) {
    int p = q[id][i];
    int fx = find(u[p]), fy = find(v[p]);
    if (fx != fy)
      Union(fx, fy), ++cnt;
    else
      ans = 0;
  }
  for (int i = 1; i <= cnt; ++i) remove();
  return ans;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    ::u[i] = u;
    ::v[i] = v;
    _[i] = w;
    S[w].push_back(std::make_pair(u, v));
  }
  scanf("%d", &_q);
  for (int i = 1; i <= _q; ++i) {
    int k;
    scanf("%d", &k);
    for (int _ = 1; _ <= k; ++_) {
      int x;
      scanf("%d", &x);
      q[i].push_back(x);
    }
    std::sort(q[i].begin(), q[i].end(), cmp);
    int t = 0;
    for (int j = 1; j <= (int)q[i].size() - 1; ++j) {
      if (_[q[i][j]] != _[q[i][j - 1]]) {
        a[_[q[i][j - 1]]].push_back(Node(i, t, j - 1));
        t = j;
      }
    }
    a[_[q[i][(int)q[i].size() - 1]]].push_back(
        Node(i, t, (int)q[i].size() - 1));
  }
  for (int i = 1; i <= n; ++i) f[i] = i, sz[i] = 1;
  for (int i = 1; i <= MAXN - 1; ++i) {
    for (auto x : a[i])
      if (!chk(x.i, x.from, x.to)) ans[x.i] = true;
    for (auto x : S[i]) Union(x.first, x.second);
  }
  for (int i = 1; i <= _q; ++i) puts(ans[i] ? "NO" : "YES");
  return 0;
}
