#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u, v, w;
} edge[500010];
struct Node {
  int u, v, bel, w;
} node[500010];
int fa[500010], flag[500010], back_up[500010], tmpf[500010];
int find(int u) {
  if (fa[u] != u) fa[u] = find(fa[u]);
  return fa[u];
}
int find2(int u) {
  if (tmpf[u] != u) tmpf[u] = find2(tmpf[u]);
  return tmpf[u];
}
bool cmp1(Edge a, Edge b) { return a.w < b.w; }
bool cmp2(Node a, Node b) {
  if (a.w != b.w) return a.w < b.w;
  return a.bel < b.bel;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    tmpf[i] = i;
  }
  memset(flag, 0, sizeof(flag));
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &edge[i].u, &edge[i].v, &edge[i].w);
  int q, tot = 0, num, id;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d", &num);
    for (int j = 0; j < num; j++) {
      scanf("%d", &id);
      node[tot].u = edge[id].u;
      node[tot].v = edge[id].v;
      node[tot].w = edge[id].w;
      node[tot++].bel = i;
    }
  }
  sort(edge + 1, edge + m + 1, cmp1);
  sort(node, node + tot, cmp2);
  int st = 1;
  for (int i = 0; i < tot; i++) {
    while (st <= m && edge[st].w < node[i].w) {
      int u = edge[st].u;
      int v = edge[st].v;
      int x = find(u);
      int y = find(v);
      if (x != y) fa[x] = y;
      st++;
    }
    int j = i;
    int cnt = 0;
    for (; j < tot && node[j].w == node[i].w && node[j].bel == node[i].bel;
         j++) {
      int u = node[j].u;
      int v = node[j].v;
      int x = find(u);
      int y = find(v);
      if (x == y) {
        flag[node[j].bel] = 1;
      } else {
        int xx = find2(x);
        int yy = find2(y);
        if (xx == yy) {
          flag[node[j].bel] = 1;
        } else {
          tmpf[xx] = yy;
          back_up[cnt++] = xx;
        }
      }
    }
    i = j - 1;
    for (int j = 0; j < cnt; j++) tmpf[back_up[j]] = back_up[j];
  }
  for (int i = 0; i < q; i++) {
    if (flag[i]) {
      printf("NO\n");
    } else {
      printf("YES\n");
    }
  }
}
