#include <bits/stdc++.h>
using namespace std;
int n, m, Q, tot;
int fa[500005], sz[500005], a[500005], ans[500005];
int val[500005], ex[500005], ey[500005];
pair<int, int> st[500005];
struct node {
  int x, y, w;
} e[500005];
bool cmp(node x, node y) { return x.w < y.w; }
bool cmp2(int x, int y) { return val[x] < val[y]; }
struct node2 {
  int w, id;
  vector<int> v;
} q[500005];
bool cmp3(node2 x, node2 y) { return x.w < y.w; }
int getfa(int x) { return fa[x] == x ? x : getfa(fa[x]); }
void merge(int x, int y) {
  int fx = getfa(x), fy = getfa(y);
  if (fx != fy) {
    if (sz[fx] > sz[fy]) swap(fx, fy);
    sz[fy] += sz[fx];
    fa[fx] = fy;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].w);
    ex[i] = e[i].x, ey[i] = e[i].y;
    val[i] = e[i].w;
  }
  sort(e + 1, e + 1 + m, cmp);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) ans[i] = 1;
  for (int i = 1; i <= Q; i++) {
    int t;
    scanf("%d", &t);
    for (int j = 1; j <= t; j++) scanf("%d", &a[j]);
    sort(a + 1, a + 1 + t, cmp2);
    for (int j = 1; j <= t;) {
      int k = j;
      while (val[a[k]] == val[a[j]] && k <= t) k++;
      q[++tot].v.resize(k - j);
      for (int l = 0; l < k - j; l++) q[tot].v[l] = a[j + l];
      q[tot].w = val[a[j]], q[tot].id = i;
      j = k;
    }
  }
  stable_sort(q + 1, q + 1 + tot, cmp3);
  for (int i = 1; i <= n; i++) fa[i] = i, sz[i] = 1;
  int p = 1;
  for (int i = 1; i <= tot;) {
    while (e[p].w < q[i].w && p <= m) {
      int x = e[p].x, y = e[p].y;
      merge(x, y);
      p++;
    }
    int j = i;
    while (q[i].w == q[j].w && j <= tot) j++;
    for (int k = i; k < j; k++) {
      int top = 0;
      for (int l = 0; l < q[k].v.size(); l++) {
        int t = q[k].v[l];
        int x = ex[t], y = ey[t];
        int fx = getfa(x), fy = getfa(y);
        if (fx != fy) {
          if (sz[fx] > sz[fy]) swap(fx, fy);
          sz[fy] += sz[fx];
          fa[fx] = fy;
          st[++top] = make_pair(fx, fy);
        } else {
          ans[q[k].id] = 0;
          break;
        }
      }
      for (int l = top; l >= 1; l--) {
        int x = st[l].first, y = st[l].second;
        sz[y] -= sz[x];
        fa[x] = x;
      }
    }
    i = j;
  }
  for (int i = 1; i <= Q; i++) puts(ans[i] ? "YES" : "NO");
  return 0;
}
