#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const long double eps = 0.2, eps2 = 0.0001;
const int INF = (int)1e9 + 2;
const long long LINF = 1e16;
const double PI = acos(-1.0);
int n, m, w[N];
int p[N], r[N];
pair<int, int> edges[N];
pair<int, int> pedges[N], redges[N];
char ok[N];
pair<int, int> ord[N];
vector<pair<int, int> > qs[N];
inline int get(int a) {
  if (p[a] == a) {
    return a;
  } else {
    return p[a] = get(p[a]);
  }
}
inline void join(int p1, int p2) {
  if (r[p1] > r[p2]) {
    swap(p1, p2);
  }
  p[p1] = p2;
  r[p2] += r[p1];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d%d", &a, &b, &w[i]);
    edges[i] = make_pair(--a, --b);
    ord[i] = make_pair(w[i], i);
  }
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 1;
  }
  sort(ord, ord + m);
  int i = 0;
  int cur = 0;
  for (; i < m;) {
    int j = i;
    while (j < m && ord[j].first == ord[i].first) {
      pedges[ord[j].second].first = get(edges[ord[j].second].first);
      pedges[ord[j].second].second = get(edges[ord[j].second].second);
      redges[ord[j].second].first = r[pedges[ord[j].second].first];
      redges[ord[j].second].second = r[pedges[ord[j].second].second];
      j++;
    }
    for (cur = i; cur < j; cur++) {
      int p1 = get(pedges[ord[cur].second].first),
          p2 = get(pedges[ord[cur].second].second);
      if (p1 != p2) {
        join(p1, p2);
      }
    }
    i = j;
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int sz;
    ok[i] = 1;
    scanf("%d", &sz);
    qs[i].resize(sz);
    for (int j = 0; j < sz; j++) {
      scanf("%d", &qs[i][j].second);
      qs[i][j].second--;
      qs[i][j].first = w[qs[i][j].second];
    }
    sort(qs[i].begin(), qs[i].end());
  }
  cur = 0;
  for (int l = 0; l < q; l++) {
    int i = 0;
    for (; i < qs[l].size();) {
      if (!ok[l]) {
        break;
      }
      int j = i;
      while (j < qs[l].size() && qs[l][j].first == qs[l][i].first) {
        int num = qs[l][j].second;
        p[edges[num].first] = pedges[num].first;
        p[edges[num].second] = pedges[num].second;
        r[pedges[num].first] = redges[num].first;
        r[pedges[num].second] = redges[num].second;
        p[pedges[num].first] = pedges[num].first;
        p[pedges[num].second] = pedges[num].second;
        j++;
      }
      for (int s = i; s < j; s++) {
        int num = qs[l][s].second;
        int p1 = get(edges[num].first), p2 = get(edges[num].second);
        if (p1 == p2) {
          ok[l] = 0;
          break;
        } else {
          join(p1, p2);
        }
      }
      i = j;
    }
  }
  for (int i = 0; i < q; i++) {
    printf((ok[i]) ? "YES\n" : "NO\n");
  }
  return 0;
}
