#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
inline int read() {
  int x = 0, k = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') k = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * k;
}
struct edge {
  int u, v, w, id, fu, fv;
} e[500086];
int n, m, q, k, f[500086];
int cmp1(edge a, edge b) { return a.w < b.w; }
int cmp2(edge a, edge b) { return a.id < b.id; }
int find(int x) {
  if (x != f[x]) return f[x] = find(f[x]);
  return f[x];
}
int main() {
  n = read(), m = read();
  for (int i = (1); i <= (m); i++) {
    e[i].u = read(), e[i].v = read(), e[i].w = read(), e[i].id = i;
  }
  for (int i = (1); i <= (n); i++) f[i] = i;
  sort(e + 1, e + 1 + m, cmp1);
  for (int i = 1; i <= m;) {
    int j = i;
    do {
      e[j].fu = find(e[j].u), e[j].fv = find(e[j].v);
      j++;
    } while (j <= m && e[j].w == e[j - 1].w);
    while (i < j) {
      int fx = find(e[i].u), fy = find(e[i].v);
      if (fx == fy && i < j) i++;
      if (i < j) f[fx] = fy;
    }
  }
  q = read();
  for (int i = (1); i <= (n); i++) f[i] = i;
  sort(e + 1, e + 1 + m, cmp2);
  while (q--) {
    k = read();
    vector<edge> h;
    for (int i = (1); i <= (k); i++) {
      int x = read();
      h.push_back({e[x].fu, e[x].fv, e[x].w});
    }
    sort(h.begin(), h.end(), cmp1);
    bool mark = true;
    for (int i = 0, tot = h.size() - 1; i <= tot && mark;) {
      if (h[i].u == h[i].v) {
        mark = false;
        break;
      }
      int fx = find(h[i].u), fy = find(h[i].v);
      f[fx] = fy;
      int j = i + 1;
      while (j <= tot && h[i].w == h[j].w) {
        int fu = find(h[j].u), fv = find(h[j].v);
        if (fu == fv) {
          mark = false;
          break;
        }
        f[fu] = fv;
        j++;
      }
      while (i < j) f[h[i].u] = h[i].u, f[h[i].v] = h[i].v, i++;
    }
    if (mark)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}
