#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long inf = (1ll << 62);
const int SQ = 400;
const int MX = 5e5 + 9;
int n, m, par[MX], x[MX], y[MX], q, edge[MX], ok[MX], k, w, sz[MX], l, r;
vector<pair<pair<int, int>, int> > v[MX];
pair<int, int> ed[MX];
int P(int x) {
  if (par[x] == x) return x;
  return par[x] = P(par[x]);
}
void merge(int x, int y) {
  x = P(x);
  y = P(y);
  if (x == y) return;
  if (sz[x] < sz[y]) swap(x, y);
  sz[x] += sz[y];
  par[y] = x;
}
void init() {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x[i], &y[i], &w);
    v[w].push_back({{x[i], y[i]}, i});
  }
  for (int i = 1; i < MX; i++) {
    for (auto pp : v[i]) {
      if (P(pp.first.first) == P(pp.first.second)) continue;
      ok[pp.second] = 1;
      ed[pp.second] = {P(pp.first.first), P(pp.first.second)};
    }
    for (auto pp : v[i]) merge(pp.first.first, pp.first.second);
  }
  init();
  scanf("%d", &q);
  while (q--) {
    scanf("%d", &k);
    bool b = 1;
    map<pair<int, int>, bool> vis;
    for (int i = 0; i < k; i++) {
      scanf("%d", &edge[i]);
      if (!ok[edge[i]] || vis.count(ed[edge[i]])) b = 0;
      if (P(x[edge[i]]) == P(y[edge[i]])) b = 0;
      vis[ed[edge[i]]] = vis[{ed[edge[i]].second, ed[edge[i]].first}] = 1;
      merge(x[edge[i]], y[edge[i]]);
    }
    for (int i = 0; i < k; i++) {
      l = x[edge[i]];
      r = y[edge[i]];
      par[l] = l;
      par[r] = r;
    }
    if (b)
      puts("YES");
    else
      puts("NO");
  }
}
