#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long maxn = 5e5 + 10, inf = 4e18, mod = 998244353;
const long double pi = 3.14159265359, eps = 1e-9;
struct edge {
  long long v, u, w;
} E[maxn], e[maxn];
long long par[maxn], sz[maxn];
pair<long long, long long> c[maxn], d[maxn];
bool jj[maxn];
long long gpar(long long v) { return (v == par[v] ? v : gpar(par[v])); }
long long t;
void mrg(long long v, long long u) {
  v = gpar(v);
  u = gpar(u);
  if (sz[v] < sz[u]) swap(v, u);
  d[++t] = make_pair(v, u);
  sz[v] += sz[u];
  par[u] = v;
}
bool cmp(pair<long long, long long> v, pair<long long, long long> u) {
  return e[v.first].w < e[u.first].w ||
         (e[v.first].w == e[u.first].w && v.second < u.second);
}
bool CMP(edge e1, edge e2) { return (e1.w < e2.w); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> E[i].v >> E[i].u >> E[i].w;
    e[i] = E[i];
  }
  sort(E + 1, E + m + 1, CMP);
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    sz[i] = 1;
  }
  long long q, kk, k, l = 0;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> k;
    for (int j = 1; j <= k; j++) {
      cin >> c[l + j].first;
      c[l + j].second = i;
    }
    l += k;
    jj[i] = 1;
  }
  sort(c + 1, c + l + 1, cmp);
  k = kk = 1;
  long long v, u;
  for (int i = 1, j; i <= (long long)5e5; i++) {
    while (k <= l && e[c[k].first].w == i) {
      j = k;
      t = 0;
      while (j <= l && c[k].second == c[j].second && e[c[j].first].w == i) {
        v = gpar(e[c[j].first].v);
        u = gpar(e[c[j].first].u);
        if (v != u)
          mrg(v, u);
        else {
          jj[c[j].second] = 0;
        }
        j++;
      }
      for (int po = t; po > 0; po--) {
        sz[d[po].first] -= sz[d[po].second];
        par[d[po].second] = d[po].second;
      }
      k = j;
    }
    while (kk <= m && E[kk].w == i) {
      v = gpar(E[kk].v);
      u = gpar(E[kk].u);
      if (v != u) mrg(v, u);
      kk++;
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << (jj[i] ? "YES" : "NO") << "\n";
  }
  return 0;
}
