#include <bits/stdc++.h>
using namespace std;
constexpr double eps = 1e-13;
constexpr int M = 1e9 + 7;
constexpr int N = 5e5 + 100;
long long qpower(long long x, long long p) {
  long long ans = 1;
  while (p) {
    if (p & 1) ans = ans * x % M;
    x = x * x % M;
    p >>= 1;
  }
  return ans;
}
vector<pair<int, int> > qw[N];
vector<int> eg[N];
int f[N], p[N], u[N], v[N], w[N];
int mt[N]{};
int T;
bool An[N]{};
int find(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = find(f[x]);
}
int find2(int x) {
  if (mt[x] != T) mt[x] = T, p[x] = f[x];
  if (p[x] != x)
    return p[x] = find2(p[x]);
  else
    return x;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> u[i] >> v[i] >> w[i];
    eg[w[i]].push_back(i);
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int qn, id;
    cin >> qn;
    for (int j = 0; j < qn; ++j) {
      cin >> id;
      --id;
      qw[w[id]].push_back(make_pair(i, id));
    }
  }
  for (int i = 0; i < n; ++i) f[i] = i;
  T = 0;
  for (int i = 1; i <= 5e5; ++i) {
    sort((qw[i]).begin(), (qw[i]).end());
    for (int j = 0; j < ((int)(qw[i]).size()); ++j) {
      int x = u[qw[i][j].second], y = v[qw[i][j].second];
      find(x);
      find(y);
    }
    for (int j = 0; j < ((int)(qw[i]).size()); ++j) {
      int x = u[qw[i][j].second], y = v[qw[i][j].second];
      if (j == 0 || qw[i][j].first != qw[i][j - 1].first) T++;
      if (find2(x) == find2(y)) An[qw[i][j].first] = 1;
      p[find2(x)] = find2(y);
    }
    for (auto id : eg[i]) {
      f[find(u[id])] = find(v[id]);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << (An[i] ? "NO" : "YES") << endl;
  }
}
