#include <bits/stdc++.h>
using namespace std;
const int N = 6e5;
int u[N], v[N], w[N], fa[N], p[N], mt[N], n, m, q, k, T, id, res[N];
vector<int> eg[N];
vector<pair<int, int> > qw[N];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int find2(int x) {
  if (mt[x] != T) mt[x] = T, p[x] = find(fa[x]);
  return p[x] == x ? x : p[x] = find2(p[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d %d", u + i, v + i, w + i);
    eg[w[i]].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++) {
      scanf("%d", &id);
      qw[w[id]].push_back({i, id});
    }
  }
  for (int i = 1; i <= 500000; i++) {
    sort(qw[i].begin(), qw[i].end());
    for (int j = 0; j < (int)qw[i].size(); j++) {
      if (j == 0 || qw[i][j].first != qw[i][j - 1].first) T++;
      if (find2(u[qw[i][j].second]) == find2(v[qw[i][j].second]))
        res[qw[i][j].first] = 1;
      p[find2(u[qw[i][j].second])] = find2(v[qw[i][j].second]);
    }
    for (int j = 0; j < (int)eg[i].size(); j++) {
      fa[find(u[eg[i][j]])] = find(v[eg[i][j]]);
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%s\n", res[i] ? "NO" : "YES");
  }
  return 0;
}
