#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 501000;
vector<int> r;
int n, m, u[N], v[N], w[N], f[N], p[N], mt[N], T, wa[N];
int Q, k, id;
vector<int> eg[N];
vector<pair<int, int>> qw[N];
vector<pair<int, int>> F;
vector<bool> cor;
typedef struct nd {
  int u, v, w;
  nd() {}
  nd(int a, int b, int c) { u = a, v = b, w = c; }
} edge;
vector<edge> E;
bool _cmp(int a, int b) { return E[a].w < E[b].w; }
bool cmp(pair<int, int> a, pair<int, int> b) {
  if (E[a.first].w != E[b.first].w) return E[a.first].w < E[b.first].w;
  return a.second < b.second;
}
int find(int x) {
  if (f[x] != x)
    return f[x] = find(f[x]);
  else
    return x;
}
int find2(int x) {
  if (mt[x] != T) mt[x] = T, p[x] = f[x];
  if (p[x] != x)
    return p[x] = find2(p[x]);
  else
    return x;
}
void add(int u, int v, int w) { E.push_back(edge(u, v, w)); }
int main() {
  int i, uu, vv, ww, q, j, o, x, l;
  scanf("%d%d", &n, &m);
  E.clear();
  for (i = 0; i < m; i++) {
    scanf("%d%d%d", &uu, &vv, &ww);
    uu--, vv--;
    add(uu, vv, ww);
    u[i] = uu, v[i] = vv, w[i] = ww;
    eg[w[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) f[i] = i;
  scanf("%d", &q);
  F.clear();
  cor.clear();
  for (j = 0; j < q; j++) {
    cor.push_back(true);
    scanf("%d", &o);
    for (i = 0; i < o; i++) {
      scanf("%d", &x);
      x--;
      F.push_back(make_pair(x, j));
      qw[w[x]].push_back(make_pair(j, x));
    }
  }
  sort(F.begin(), F.end(), cmp);
  r.clear();
  for (i = 0; i < m; i++) r.push_back(i);
  sort(r.begin(), r.end(), _cmp);
  j = 0, l = 0;
  for (int i = 1; i < 500001; i++) {
    sort((qw[i]).begin(), (qw[i]).end());
    for (int jj = 0; jj < ((int)(qw[i]).size()); jj++) {
      int x = u[qw[i][jj].second], y = v[qw[i][jj].second];
      find(x);
      find(y);
    }
    k = j;
    for (; j < F.size() && E[F[j].first].w == i; j++) {
      F[j] = make_pair(qw[i][j - k].second, qw[i][j - k].first);
      if (j == k || F[j].second != F[j - 1].second) T++;
      int x = u[F[j].first], y = v[F[j].first];
      if (find2(x) == find2(y)) wa[F[j].second] = 1;
      p[find2(x)] = find2(y);
    }
    if (j - k != ((int)(qw[i]).size()))
      while (1)
        ;
    for (; l < m && E[r[l]].w == i; l++) {
      int x = E[r[l]].u, y = E[r[l]].v;
      f[find(x)] = find(y);
    }
  }
  for (int i = 0; i < q; i++) puts(wa[i] ? "NO" : "YES");
}
