#include <bits/stdc++.h>
using namespace std;
const int M = 500005;
int read() {
  int x = 0, flag = 1;
  char c;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') flag = -1;
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  return x * flag;
}
int n, m, q, p[M];
struct edge {
  int u, v, c, id, tx, ty;
  bool operator<(const edge &B) const { return c < B.c; }
} e[M];
void make() {
  for (int i = 1; i <= n; i++) p[i] = i;
}
int find(int x) {
  if (p[x] ^ x) p[x] = find(p[x]);
  return p[x];
}
void merge(int x, int y) { p[find(x)] = find(y); }
bool cmp(edge x, edge y) { return x.id < y.id; }
int main() {
  n = read();
  m = read();
  make();
  for (int i = 1; i <= m; i++) {
    e[i].u = read();
    e[i].v = read();
    e[i].c = read();
    e[i].id = i;
  }
  sort(e + 1, e + 1 + m);
  for (int i = 1; i <= m;) {
    int j = i;
    for (; e[i].c == e[j].c; j++) {
      e[j].tx = find(e[j].u);
      e[j].ty = find(e[j].v);
    }
    for (; i < j; i++) {
      if (find(e[i].u) ^ find(e[i].v)) merge(e[i].u, e[i].v);
    }
  }
  q = read();
  sort(e + 1, e + 1 + m, cmp);
  make();
  while (q--) {
    int k = read();
    vector<edge> g;
    for (int i = 1; i <= k; i++) {
      int x = read();
      g.push_back(edge{e[x].tx, e[x].ty, e[x].c, 0, 0, 0});
    }
    sort(g.begin(), g.end());
    bool flag = 1;
    for (int i = 0; i < k && flag;) {
      int j = i;
      while (j < k && g[j].c == g[i].c) {
        if (find(g[j].u) == find(g[j].v)) {
          flag = 0;
          break;
        }
        merge(g[j].u, g[j].v);
        j++;
      }
      for (; i < j; i++) p[g[i].u] = g[i].u, p[g[i].v] = g[i].v;
    }
    if (flag)
      puts("YES");
    else
      puts("NO");
  }
}
