#include <bits/stdc++.h>
using namespace std;
vector<pair<pair<int, int>, pair<int, int> > > edg;
int const M = 5e5 + 10, inf = 1e9 + 10;
int p[M], h[M], a[M], b[M], w[M], mark[M], root[M], cnt = 1, ind[M];
vector<pair<pair<int, int>, int> > hlp;
bool mark2[M];
int fp(int x) {
  if (p[x] == 0) return x;
  return fp(p[x]);
}
int mrg(int a, int b) {
  if (a == b) return -1;
  if (h[a] > h[b])
    h[a] = max(h[a], h[b] + 1), p[b] = a;
  else
    h[b] = max(h[a] + 1, h[b]), p[a] = b;
  return 1;
}
int main() {
  int n, m;
  cin >> n >> m;
  int tt = 0;
  edg.push_back(make_pair(make_pair(tt, tt), make_pair(tt, tt)));
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &a[i], &b[i], &w[i]);
    edg.push_back(make_pair(make_pair(w[i], i), make_pair(a[i], b[i])));
  }
  sort(edg.begin(), edg.end());
  for (int i = 1; i <= n; i++) h[i] = 1;
  int last = 1;
  edg.push_back(make_pair(make_pair(inf, inf), make_pair(inf, inf)));
  for (int i = 1; i <= m + 1; i++) {
    if (i != 1 && edg[i].first.first != edg[i - 1].first.first) {
      sort(hlp.begin(), hlp.end());
      for (int j = last; j < i; j++) {
        mrg(fp(edg[j].second.first), fp(edg[j].second.second));
      }
      for (int j = 0; j < hlp.size(); j++) {
        if (j != 0 && hlp[j].first.first == hlp[j - 1].first.first &&
            hlp[j].first.second == hlp[j - 1].first.second)
          root[hlp[j].second] = cnt;
        else
          root[hlp[j].second] = ++cnt;
      }
      hlp.clear();
      last = i;
    }
    if (i == m + 1) continue;
    int p1 = fp(edg[i].second.first);
    int p2 = fp(edg[i].second.second);
    hlp.push_back(
        make_pair(make_pair(min(p1, p2), max(p1, p2)), edg[i].first.second));
    if (p1 == p2) {
      mark[edg[i].first.second] = 1;
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= n; i++) p[i] = 0, h[i] = 1;
  while (q--) {
    int t;
    cin >> t;
    bool flag = 0;
    for (int i = 1; i <= t; i++) {
      scanf("%d", &ind[i]);
      if (mrg(fp(a[ind[i]]), fp(b[ind[i]])) == -1 || mark2[root[ind[i]]])
        flag = 1;
      mark2[root[ind[i]]] = 1;
      if (mark[ind[i]]) {
        flag = 1;
      }
    }
    if (flag)
      printf("NO\n");
    else
      printf("YES\n");
    for (int i = 1; i <= t; i++)
      p[a[ind[i]]] = 0, h[a[ind[i]]] = 1, p[b[ind[i]]] = 0, h[b[ind[i]]] = 1,
      mark2[root[ind[i]]] = 0;
  }
}
