#include <bits/stdc++.h>
using namespace std;
int rd() {
  char c = getchar();
  int s = 0, f = 1;
  while (c > '9' || c < '0') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') s = s * 10 + c - '0', c = getchar();
  return s * f;
}
const int N = 2000200;
int n, m, fa[N], ch[N][2], st[N], rev[N];
int val[N], mx[N], f[N], q, b[N], c[N];
struct hh {
  int x, y, w, id;
} a[N];
void swap(int &a, int &b) {
  if (a != b) a ^= b, b ^= a, a ^= b;
}
int isroot(int u) { return ch[fa[u]][0] != u && ch[fa[u]][1] != u; }
int get(int u) { return ch[fa[u]][1] == u; }
void update(int u) {
  int p = max(val[u], max(val[mx[ch[u][0]]], val[mx[ch[u][1]]]));
  if (p == val[u])
    mx[u] = u;
  else if (p == val[mx[ch[u][0]]])
    mx[u] = mx[ch[u][0]];
  else
    mx[u] = mx[ch[u][1]];
}
void down(int u) {
  if (rev[u]) {
    rev[u] = 0;
    rev[ch[u][0]] ^= 1;
    rev[ch[u][1]] ^= 1;
    swap(ch[u][0], ch[u][1]);
  }
}
void rotate(int u) {
  int v = fa[u], w = fa[v], x = get(u);
  if (!isroot(v)) ch[w][get(v)] = u;
  fa[u] = w;
  ch[v][x] = ch[u][x ^ 1];
  fa[ch[u][x ^ 1]] = v;
  ch[u][x ^ 1] = v;
  fa[v] = u;
  update(v);
  update(u);
}
void splay(int u) {
  st[st[0] = 1] = u;
  for (int i = u; !isroot(i); i = fa[i]) st[++st[0]] = fa[i];
  for (int i = st[0]; i; i--) down(st[i]);
  for (; !isroot(u); rotate(u))
    if (!isroot(fa[u])) rotate(get(u) == get(fa[u]) ? fa[u] : u);
}
void access(int u) {
  for (int i = 0; u; i = u, u = fa[u]) splay(u), ch[u][1] = i, update(u);
}
void makeroot(int u) {
  access(u);
  splay(u);
  rev[u] ^= 1;
}
void link(int u, int v) {
  makeroot(u);
  fa[u] = v;
}
void cut(int u, int v) {
  makeroot(u);
  access(v);
  splay(v);
  if (fa[u] != v || ch[u][1]) return;
  fa[u] = ch[v][0] = 0;
}
int query(int u, int v) {
  makeroot(u);
  access(v);
  splay(v);
  return mx[v];
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
int main() {
  n = rd(), m = rd();
  for (int i = 1; i <= m; i++) {
    a[i].x = rd();
    a[i].y = rd();
    a[i].w = rd();
    a[i].id = n + i;
    val[n + i] = mx[n + i] = a[i].w;
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1, x, y; i <= m; i++) {
    x = find(a[i].x);
    y = find(a[i].y);
    if (x == y) {
      x = query(a[i].x, a[i].y) - n;
      if (a[x].w <= a[i].w) continue;
      cut(a[x].x, a[x].id);
      cut(a[x].id, a[x].y);
      link(a[i].x, a[i].id);
      link(a[i].id, a[i].y);
    } else
      f[x] = y, link(a[i].x, a[i].id), link(a[i].id, a[i].y);
  }
  a[0].w = -1;
  q = rd();
  while (q--) {
    int p = rd(), opt = 1, cnt = 0;
    for (int i = 1, v; i <= p; i++) {
      v = b[i] = rd();
      if (opt) {
        int x = query(a[v].x, a[v].y) - n;
        if (x < 0 || a[x].w < a[v].w) {
          opt = 0;
          continue;
        }
        c[++cnt] = val[a[v].id];
        if (x != v) {
          cut(a[x].x, a[x].id);
          cut(a[x].id, a[x].y);
          val[a[v].id] = 0;
          link(a[v].x, a[v].id);
          link(a[v].id, a[v].y);
        } else
          val[a[v].id] = 0, splay(a[v].id);
      }
    }
    puts(opt ? "YES" : "NO");
    for (int i = 1; i <= cnt; i++) val[a[b[i]].id] = c[i], splay(a[b[i]].id);
  }
}
