#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 100;
int f[N];
struct node {
  int u, v, w;
  bool operator<(const node& a) const { return w < a.w; }
};
struct qq {
  int id, u, v, w;
  bool operator<(const qq& a) const {
    if (a.w == w) return id < a.id;
    return w < a.w;
  }
};
vector<pair<int, int> > v;
qq q[N];
node pt[N];
bool vis[N];
int Find(int x, bool tmp) {
  if (tmp) v.push_back({x, f[x]});
  return x == f[x] ? x : f[x] = Find(f[x], tmp);
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", &pt[i].u, &pt[i].v, &pt[i].w);
  }
  int qs;
  cin >> qs;
  int tot = 0;
  for (int i = 1; i <= qs; i++) {
    int k;
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      q[tot].id = i;
      int now;
      scanf("%d", &now);
      q[tot].u = pt[now].u;
      q[tot].v = pt[now].v;
      q[tot].w = pt[now].w;
      tot++;
    }
  }
  sort(q, q + tot);
  sort(pt + 1, pt + 1 + m);
  int cnt = 0;
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    while (cnt < tot && q[cnt].w == pt[i].w) {
      queue<qq> que;
      que.push(q[cnt]);
      int tmp = q[cnt].id;
      for (int j = cnt + 1; j <= tot; j++) {
        if (q[j].w == q[j - 1].w && q[j].id == q[j - 1].id)
          que.push(q[j]);
        else {
          cnt = j;
          break;
        }
      }
      bool res = true;
      while (!que.empty()) {
        qq now = que.front();
        que.pop();
        int f1 = Find(now.u, true);
        int f2 = Find(now.v, true);
        if (f1 == f2) {
          res = false;
          break;
        }
        f[f1] = f2;
        v.push_back({f1, f1});
      }
      if (res == false) vis[tmp] = true;
      for (int i = v.size() - 1; i >= 0; i--) {
        f[v[i].first] = v[i].second;
      }
      v.clear();
    }
    int f1 = Find(pt[i].u, false);
    int f2 = Find(pt[i].v, false);
    if (f1 == f2) continue;
    f[f1] = f2;
  }
  int cns = 0;
  for (int i = 1; i <= n; i++)
    if (Find(i, false) == i) cns++;
  if (cns >= 2) {
    for (int i = 1; i <= qs; i++) {
      puts("NO");
    }
  } else {
    for (int i = 1; i <= qs; i++) {
      if (vis[i])
        puts("NO");
      else
        puts("YES");
    }
  }
  return 0;
}
