#include <bits/stdc++.h>
using namespace std;
struct node {
  int u, v, data, num;
  bool operator<(const node &a) const {
    if (data != a.data) return data < a.data;
    return num < a.num;
  }
};
node edge[500001], edges[500001];
int n, m, q, f[500001], Ans[500001], length, length2;
node tong[500001], tong2[500001];
int read() {
  char c = 0;
  int sum = 0;
  while (c < '0' || c > '9') c = getchar();
  while ('0' <= c && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int rt[500001];
int find(int x) {
  if (rt[x] == x) return x;
  return rt[x] = find(rt[x]);
}
void unionn(int x, int y) {
  if (x != y) rt[x] = y;
  return;
}
int main() {
  int x, y;
  n = read(), m = read();
  for (int i = 1; i <= m; ++i)
    edge[i].u = edges[i].u = read(), edge[i].v = edges[i].v = read(),
    edge[i].data = edges[i].data = read();
  sort(edges + 1, edges + m + 1);
  for (int i = 1; i <= n; ++i) rt[i] = i;
  q = read();
  for (int i = 1; i <= q; ++i) {
    Ans[i] = 1;
    x = read();
    while (x--) {
      y = read();
      tong[++length] = (node){edge[y].u, edge[y].v, edge[y].data, i};
    }
  }
  sort(tong + 1, tong + length + 1);
  int pos = 0;
  for (int i = 1; i <= length; ++i) {
    while (pos < m && edges[pos + 1].data < tong[i].data)
      pos++, unionn(find(edges[pos].u), find(edges[pos].v));
    if (find(tong[i].u) == find(tong[i].v))
      Ans[tong[i].num] = 0;
    else
      tong2[++length2] =
          (node){find(tong[i].u), find(tong[i].v), tong[i].data, tong[i].num};
  }
  sort(tong2 + 1, tong2 + length2 + 1);
  for (int i = 1; i <= n; ++i) rt[i] = i;
  int prelength = 0;
  for (int i = 1; i <= length2; ++i) {
    if (tong2[i].data != tong2[i - 1].data ||
        tong2[i].num != tong2[i - 1].num) {
      for (int j = prelength; j <= i - 1; ++j)
        rt[tong2[j].u] = tong2[j].u, rt[tong2[j].v] = tong2[j].v;
      prelength = i;
    }
    if (find(tong2[i].u) == find(tong2[i].v)) Ans[tong2[i].num] = 0;
    unionn(find(tong2[i].u), find(tong2[i].v));
  }
  for (int i = 1; i <= q; ++i) {
    if (Ans[i])
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}
