#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 501000;
int n, m, u[N], v[N], w[N], f[N], p[N], mt[N], T, wa[N];
int Q, k, id;
vector<int> eg[N];
vector<pair<int, int> > qw[N];
int find(int x) {
  if (f[x] != x)
    return f[x] = find(f[x]);
  else
    return 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() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", u + i, v + i, w + i);
    eg[w[i]].push_back(i);
  }
  for (int i = 1; i < n + 1; i++) f[i] = i;
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &id);
      --id;
      qw[w[id]].push_back(make_pair(i, id));
    }
  }
  for (int i = 1; i < 500001; 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];
    }
    for (int j = 0; j < ((int)(qw[i]).size()); j++) {
      if (j == 0 || qw[i][j].first != qw[i][j - 1].first) T++;
      int x = u[qw[i][j].second], y = v[qw[i][j].second];
      if (find2(x) == find2(y)) wa[qw[i][j].first] = 1;
      p[find2(x)] = find2(y);
    }
    for (auto id : eg[i]) {
      int x = u[id], y = v[id];
      f[find(x)] = find(y);
    }
  }
  for (int i = 0; i < Q; i++) puts(wa[i] ? "NO" : "YES");
}
