#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& os, vector<long long>& x) {
  for (long long i = 0; i < x.size(); i++) os << x[i] << ' ';
  return os;
}
ostream& operator<<(ostream& os, pair<long long, long long> x) {
  cout << x.first << ' ' << x.second << ' ';
  return os;
}
ostream& operator<<(ostream& os, vector<pair<long long, long long> >& x) {
  for (long long i = 0; i < x.size(); i++) os << x[i] << '\n';
  return os;
}
vector<pair<long long, long long> > changed;
bool mark[500005];
struct dsu {
  long long par[500005];
  dsu() {
    for (long long i = 1; i <= 500005 - 5; i++) par[i] = i;
  }
  long long find(long long x, bool cache = false) {
    if (cache) {
      if (!mark[x]) {
        mark[x] = true;
        changed.push_back(make_pair(x, par[x]));
      }
    }
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  bool uni(long long x, long long y, bool cache = false) {
    x = find(x, cache);
    y = find(y, cache);
    if (x != y) {
      if (cache) {
        if (!mark[x]) {
          mark[x] = true;
          changed.push_back(make_pair(x, par[x]));
        }
      }
      par[x] = y;
      return true;
    }
    return false;
  }
} d;
struct data {
  long long u, v, c;
  data(long long _u, long long _v, long long _c) : u(_u), v(_v), c(_c){};
};
bool byPrice(data x, data y) { return x.c < y.c; }
long long n, m, q;
vector<data> edge;
vector<data> oredge;
vector<vector<vector<long long> > > query(500005);
vector<vector<pair<long long, long long> > > withW(500005);
vector<vector<long long> > tmp(500005);
bool ans[500005];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (long long i = 1; i <= m; i++) {
    long long u, v, c;
    cin >> u >> v >> c;
    edge.push_back(data(u, v, c));
    withW[c].push_back(make_pair(u, v));
  }
  cin >> q;
  for (long long i = 1; i <= q; i++) {
    long long num;
    cin >> num;
    vector<long long> zz;
    while (num--) {
      long long t;
      cin >> t;
      t--;
      zz.push_back(t);
      tmp[edge[t].c].push_back(t);
    }
    for (long long j = 0; j < zz.size(); j++) {
      long long c = edge[zz[j]].c;
      if (tmp[c].empty()) continue;
      tmp[c].push_back(i);
      query[c].push_back(tmp[c]);
      tmp[c].clear();
    }
  }
  memset(ans, 1, sizeof(ans));
  for (long long w = 1; w <= 500000; w++) {
    for (long long i = 0; i < query[w].size(); i++) {
      for (long long j = 0; j < query[w][i].size() - 1; j++) {
        long long num = query[w][i][j];
        assert(edge[num].c == w);
        long long u = edge[num].u;
        long long v = edge[num].v;
        d.find(u);
        d.find(v);
      }
    }
    for (long long i = 0; i < query[w].size(); i++) {
      long long which = query[w][i].back();
      bool ok = true;
      for (long long j = 0; j < query[w][i].size() - 1; j++) {
        long long num = query[w][i][j];
        long long u = edge[num].u;
        long long v = edge[num].v;
        if (!d.uni(u, v, 1)) {
          ok = false;
          break;
        }
      }
      if (!ok) {
        ans[which] = false;
      }
      for (long long j = 0; j < changed.size(); j++) {
        d.par[changed[j].first] = changed[j].second;
        mark[changed[j].first] = false;
      }
      changed.clear();
    }
    for (long long i = 0; i < withW[w].size(); i++) {
      long long u = withW[w][i].first;
      long long v = withW[w][i].second;
      d.uni(u, v);
    }
  }
  for (long long i = 1; i <= q; i++) {
    if (ans[i] == 1)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
