#include <bits/stdc++.h>
using namespace std;
long long n;
long long k, m;
long long mod = 1e9 + 7;
vector<int> ar, tag;
vector<vector<int> > graph;
int gcd(int a, int b) {
  if (a == 1 || b == 1) return 1;
  if (a > b) {
    int t = a;
    a = b;
    b = t;
  }
  if (b % a == 0) return a;
  return gcd(b % a, a);
}
int fa[500005], p[500005];
int v[500005], u[500005], w[500005], res[500005], mt[500005];
vector<int> ed[500005];
int T;
vector<pair<int, int> > qed[500005];
int parent(int a) { return fa[a] == a ? a : fa[a] = parent(fa[a]); }
int parent2(int a) {
  if (mt[a] != T) mt[a] = T, p[a] = fa[a];
  return p[a] == a ? a : p[a] = parent2(p[a]);
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    ed[w[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> k;
    while (k--) {
      int id;
      cin >> id;
      qed[w[id]].push_back({i, id});
    }
  }
  for (int i = 1; i <= 500000; i++) {
    sort(qed[i].begin(), qed[i].end());
    for (int j = 0; j < qed[i].size(); j++) {
      if (j == 0 || qed[i][j - 1].first != qed[i][j].first) T++;
      if (parent2(u[qed[i][j].second]) == parent2(v[qed[i][j].second]))
        res[qed[i][j].first] = 1;
      p[parent2(u[qed[i][j].second])] = parent2(v[qed[i][j].second]);
    }
    for (int j = 0; j < ed[i].size(); j++) {
      fa[parent(u[ed[i][j]])] = parent(v[ed[i][j]]);
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%s\n", res[i] ? "NO" : "YES");
  }
  return 0;
}
