#include <bits/stdc++.h>
using namespace std;
const int M = 500010, N = M, C = N, Q = C;
struct edge {
  int x, y, z;
  const bool operator<(const edge &_) const { return z < _.z; }
} e[M];
int n, m, q, t;
bool b[Q];
int fa[N], tt[N], cha[N];
inline void init() {
  for (int i = 1; i <= n; i++) fa[i] = i;
}
inline int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
inline int findt(int x) {
  if (cha[x] < t) cha[x] = t, tt[x] = fa[x];
  return tt[x] == x ? x : tt[x] = findt(tt[x]);
}
inline bool unite(int x, int y, bool f) {
  if (f)
    x = findt(x), y = findt(y);
  else
    x = find(x), y = find(y);
  if (x == y) return 0;
  if (f)
    tt[x] = y;
  else
    fa[x] = y;
  return 1;
}
vector<pair<int, int> > g[C], gg[C];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++)
    scanf("%d%d%d", &e[i].x, &e[i].y, &e[i].z),
        gg[e[i].z].push_back(make_pair(e[i].x, e[i].y));
  scanf("%d", &q);
  for (int i = 1, x, y; i <= q; i++)
    for (scanf("%d", &x); (x--) && (scanf("%d", &y));)
      g[e[y].z].push_back(make_pair(i, y));
  init();
  for (int i = 1; i <= C - 10; i++) {
    if (g[i].size()) {
      for (int j = 0; j < (int)g[i].size(); ++j) {
        t += (j == 0 || g[i][j].first > g[i][j - 1].first);
        int ind = g[i][j].second;
        if (!unite(e[ind].x, e[ind].y, 1)) b[g[i][j].first] = 1;
      }
    }
    if (gg[i].size())
      for (vector<pair<int, int> >::iterator it = gg[i].begin();
           it != gg[i].end(); ++it)
        unite(it->first, it->second, 0);
  }
  for (int i = 1; i <= q; i++) puts(b[i] ? "NO" : "YES");
}
