#include <bits/stdc++.h>
using namespace std;
int n, m, q, tot, ans[500010], mark[500010], pa[500010], tmp, fa[500010];
struct Edge {
  int a, b, c;
  bool operator<(const Edge &x) const { return c < x.c; }
} e[500010], ed[500010];
struct info {
  int a, b;
  bool operator<(const info &x) const {
    return (e[a].c != e[x.a].c) ? e[a].c < e[x.a].c : b < x.b;
  }
} t[500010];
int find(int x) {
  if (!fa[x]) return x;
  return fa[x] = find(fa[x]);
}
int find2(int x) {
  if (mark[x] != tmp) pa[x] = fa[x], mark[x] = tmp;
  if (!pa[x]) return x;
  return pa[x] = find2(pa[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, a, b, c; i <= m; i++)
    scanf("%d%d%d", &a, &b, &c), e[i] = (Edge){a, b, c}, ed[i] = e[i];
  scanf("%d", &q);
  for (int i = 1, k, x; i <= q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) scanf("%d", &x), t[++tot] = (info){x, i};
  }
  sort(t + 1, t + tot + 1), sort(ed + 1, ed + m + 1);
  for (int i = 1, pos = 1, po = 1, fa_x, fa_y, x; i <= tot; i = pos) {
    while (ed[po].c < e[t[i].a].c && po <= m) {
      fa_x = find(ed[po].a), fa_y = find(ed[po].b);
      if (fa_x != fa_y) fa[fa_y] = fa_x;
      po++;
    }
    while (e[t[pos].a].c == e[t[i].a].c && pos <= tot) {
      if (t[pos].b != t[pos - 1].b || pos == i) tmp++;
      x = t[pos].a, fa_x = find2(e[x].a), fa_y = find2(e[x].b);
      if (fa_x == fa_y)
        ans[t[pos].b] = 1;
      else
        pa[fa_y] = fa_x;
      pos++;
    }
  }
  for (int i = 1; i <= q; i++)
    if (!ans[i])
      printf("YES\n");
    else
      printf("NO\n");
}
