#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
struct node {
  int u, v, w, t, uu, vv;
} e[N];
bool cmp1(const node& a, const node& b) { return a.w < b.w; }
bool cmp2(const node& a, const node& b) { return a.t < b.t; }
int fa[N], n, m;
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d%d", &n, &m);
  for (register int i = 1; i <= m; ++i) {
    scanf("%d%d%d", &e[i].u, &e[i].v, &e[i].w);
    e[i].t = i;
  }
  sort(e + 1, e + 1 + m, cmp1);
  for (register int i = 1; i <= n; ++i) fa[i] = i;
  for (register int i = 1; i <= m;) {
    int j = i;
    do {
      e[j].uu = find(e[j].u);
      e[j].vv = find(e[j].v);
      j++;
    } while (j <= m && e[j].w == e[j - 1].w);
    while (i < j) {
      while (i < j && find(e[i].u) == find(e[i].v)) i++;
      if (i < j) fa[find(e[i].u)] = find(e[i].v);
    }
  }
  sort(e + 1, e + 1 + m, cmp2);
  for (register int i = 1; i <= n; ++i) fa[i] = i;
  int Q, x;
  scanf("%d", &Q);
  while (Q--) {
    int p;
    bool OK = 1;
    vector<node> v;
    scanf("%d", &p);
    for (register int i = 1; i <= p; ++i) {
      scanf("%d", &x);
      v.push_back((node){e[x].uu, e[x].vv, e[x].w, e[x].t, 0, 0});
    }
    sort(v.begin(), v.end(), cmp1);
    for (register int i = 0; i < p && OK;) {
      if (v[i].u == v[i].v) {
        OK = 0;
        break;
      }
      fa[find(v[i].u)] = find(v[i].v);
      int j = i + 1;
      while (j < p && v[i].w == v[j].w) {
        if (find(v[j].u) == find(v[j].v)) {
          OK = 0;
          break;
        }
        fa[find(v[j].u)] = find(v[j].v);
        j++;
      }
      while (i < j) fa[v[i].u] = v[i].u, fa[v[i].v] = v[i].v, i++;
    }
    if (OK)
      printf("YES\n");
    else
      printf("NO\n");
  }
}
