#include <bits/stdc++.h>
const double PI = acos(-1.0);
const double eps = 1e-6;
const int maxm = 5e5 + 100;
const int maxn = 5e5 + 100;
using namespace std;
int n, m, q;
int t;
vector<pair<int, int> > Q[maxn];
bool vis[maxn];
int idx[maxn];
int f[maxn];
void init() {
  for (int i = 1; i <= n; i++) f[i] = i;
  memset(idx, 0, sizeof(idx));
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
bool same(int x, int y) { return find(x) == find(y); }
void unit(int x, int y) {
  x = find(x);
  y = find(y);
  if (x != y) f[x] = y;
}
struct edge {
  int u, v, cost;
};
bool cmp(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
edge es[maxm], et[maxm];
int top = 0, val[maxn];
int* s[maxn];
int find_(int x) {
  if (x == f[x]) return x;
  return find_(f[x]);
}
void reload() {
  while (top) {
    (*s[top]) = val[top];
    --top;
  }
}
void solve(int& w) {
  int ed = Q[w].size();
  int r = -1;
  for (int j = 0; j < ed; j++) {
    pair<int, int> l;
    l = Q[w][j];
    int y = l.first;
    if (!vis[y]) continue;
    int x = l.second;
    if (y > r) {
      reload();
      r = y;
    };
    int p1 = find_(et[x].u);
    int p2 = find_(et[x].v);
    if (p1 != p2) {
      s[++top] = f + p1;
      val[top] = f[p1];
      f[p1] = p2;
    } else
      vis[y] = false;
  }
  reload();
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &es[i].u, &es[i].v, &es[i].cost);
    et[i] = es[i];
  }
  sort(es + 1, es + m + 1, cmp);
  scanf("%d", &q);
  memset(vis, true, sizeof(vis));
  for (int i = 0; i < q; i++) {
    int len;
    scanf("%d", &len);
    for (int j = 0; j < len; j++) {
      scanf("%d", &t);
      pair<int, int> pt;
      int w = et[t].cost;
      pt.first = i;
      pt.second = t;
      Q[w].push_back(pt);
    }
  }
  int value = -1;
  for (int i = 1; i <= m; i++) {
    edge e = es[i];
    if (e.cost > value) {
      value = e.cost;
      solve(value);
    }
    if (!same(e.u, e.v)) unit(e.u, e.v);
  }
  for (int i = 0; i < q; i++)
    if (vis[i])
      printf("YES\n");
    else
      printf("NO\n");
  return 0;
}
