#include <bits/stdc++.h>
using namespace std;
int fa[500005];
struct node {
  int opt, u, v, w, uu, vv;
  bool operator<(const node &a) const { return w < a.w; }
} E[500005];
int n, m, Q;
int find(int x) {
  while (x != fa[x]) x = fa[x] = fa[fa[x]];
  return x;
}
pair<int, int> stck[500005];
int top;
void merge(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  fa[x] = y;
}
bool cmp(node x, node y) { return x.opt < y.opt; }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    E[i] = (node){i, u, v, w, u, v};
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  sort(E + 1, E + m + 1);
  for (int i = 1; i <= m;) {
    int j = i;
    while (E[j].w == E[i].w) {
      E[j].uu = find(E[j].u), E[j].vv = find(E[j].v);
      j++;
    }
    while (i < j) {
      merge(E[i].u, E[i].v);
      i++;
    }
  }
  sort(E + 1, E + m + 1, cmp);
  for (int i = 1; i <= n; i++) fa[i] = i;
  cin >> Q;
  while (Q--) {
    int k;
    scanf("%d", &k);
    vector<node> V;
    for (int i = 1; i <= k; i++) {
      int x;
      scanf("%d", &x);
      V.push_back(E[x]);
    }
    sort(V.begin(), V.end());
    int j = 0;
    bool flag = 0;
    for (int i = 0; i < V.size();) {
      if (V[i].uu == V[i].vv) {
        flag = 1;
        break;
      }
      merge(V[i].uu, V[i].vv);
      j = i + 1;
      while (j < V.size() && V[j].w == V[i].w) {
        int u = find(V[j].uu), v = find(V[j].vv);
        if (u == v) {
          flag = 1;
          break;
        }
        fa[u] = v;
        j++;
      }
      while (i < j) fa[V[i].uu] = V[i].uu, fa[V[i].vv] = V[i].vv, i++;
      if (flag) break;
    }
    if (!flag)
      puts("YES");
    else
      puts("NO");
  }
}
