#include <bits/stdc++.h>
using namespace std;
int n, m, fa[500000 + 1], q, to[500000 + 1], opt[500000 + 1];
struct node {
  int u, v, w, id, fau, fav;
  bool operator<(const node a) const { return w < a.w; }
} e[500000 + 1];
void read(int &x) {
  char ch;
  bool ok;
  for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar())
    if (ch == '-') ok = 1;
  for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar())
    ;
  if (ok) x = -x;
}
bool cmp(int x, int y) { return e[x].w < e[y].w; }
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i <= m; ++i)
    read(e[i].u), read(e[i].v), read(e[i].w), e[i].id = i;
  sort(e + 1, e + m + 1);
  for (int i = 1; i <= m; ++i) to[e[i].id] = i;
  for (int i = 0; i <= m; ++i) {
    fa[find(e[i].u)] = find(e[i].v);
    if (e[i].w != e[i + 1].w) {
      int now = i + 1;
      while (e[now].w == e[i + 1].w && now <= m) {
        e[now].fau = find(e[now].u);
        e[now].fav = find(e[now].v);
        now++;
      }
    }
  }
  read(q);
  while (q--) {
    int k, f = 1;
    read(k);
    for (int i = 1; i <= k; ++i) read(opt[i]), opt[i] = to[opt[i]];
    sort(opt + 1, opt + k + 1, cmp);
    for (int i = 1; i <= k;) {
      int now = i;
      while (e[opt[now]].w == e[opt[i]].w && now <= k) {
        fa[e[opt[now]].fau] = e[opt[now]].fau;
        fa[e[opt[now]].fav] = e[opt[now]].fav;
        now++;
      }
      now = i;
      while (e[opt[now]].w == e[opt[i]].w && now <= k) {
        int fau = find(e[opt[now]].fau), fav = find(e[opt[now]].fav);
        if (fau == fav) {
          f = 0;
          break;
        }
        fa[fau] = fav;
        now++;
      }
      if (!f) break;
      i = now;
    }
    if (f)
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
