#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << "=" << h << "\n";
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << "=" << h << ",";
  _dbg(sdbg + 1, a...);
}
const int MX = 500007;
int pocz[MX], kon[MX], wag[MX];
pair<int, int> ktore[MX];
vector<int> v[MX];
vector<int> zbior[MX];
int ojciec[MX];
vector<pair<int, int> > G[MX];
int odp[MX];
long long int zumo;
vector<int> pom;
set<pair<int, int> > S;
void Union(int a, int b, int weight) {
  if ((a = ojciec[a]) == (b = ojciec[b])) return;
  zumo += weight;
  if (zbior[a].size() > zbior[b].size()) swap(a, b);
  for (int u : zbior[a]) {
    for (pair<int, int> p : G[u]) {
      int V = p.first;
      if (ojciec[V] == b) odp[p.second] = weight;
    }
  }
  zbior[b].resize(zbior[a].size() + zbior[b].size());
  for (int x : zbior[a]) {
    ojciec[x] = b;
    zbior[b].push_back(x);
  }
}
int rep[MX], rnk[MX];
int znajdz(int x) { return rep[x] = (rep[x] == x ? x : znajdz(rep[x])); }
bool polacz(int a, int b) {
  if ((a = znajdz(a)) == (b = znajdz(b))) return 0;
  if (rnk[a] > rnk[b]) swap(a, b);
  rep[a] = b;
  rnk[b] = max(rnk[b], rnk[a] + 1);
  return 1;
}
vector<int> zap;
int32_t main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &pocz[i], &kon[i], &wag[i]);
    G[pocz[i]].push_back({kon[i], i});
    G[kon[i]].push_back({pocz[i], i});
    v[wag[i]].push_back(i);
  }
  for (int i = 1; i <= n; ++i) zbior[i].push_back(i), ojciec[i] = i;
  for (int i = 1; i <= 500000; ++i) {
    for (int x : v[i]) {
      int a = pocz[x], b = kon[x];
      ktore[x] = {min(ojciec[a], ojciec[b]), max(ojciec[a], ojciec[b])};
    }
    for (int x : v[i]) {
      int a = pocz[x], b = kon[x];
      Union(a, b, i);
    }
  }
  for (int i = 1; i <= n; ++i) rep[i] = i, rnk[i] = 0;
  int q;
  scanf("%d", &q);
  while (q--) {
    int roz;
    scanf("%d", &roz);
    zap.clear();
    bool czy = 1;
    S.clear();
    for (int i = 1; i <= roz; ++i) {
      int x;
      scanf("%d", &x);
      zap.push_back(x);
      czy = min(czy, polacz(pocz[x], kon[x]));
      czy = min(czy, odp[x] == wag[x]);
      if (S.find(ktore[x]) != S.end()) czy = 0;
      S.insert(ktore[x]);
    }
    puts(czy ? "YES" : "NO");
    for (int x : zap)
      rep[pocz[x]] = pocz[x], rnk[pocz[x]] = 0, rep[kon[x]] = kon[x],
      rnk[kon[x]] = 0;
  }
}
