#include <bits/stdc++.h>
using namespace std;
const long long MXN = 200 + 10;
const long long MXM = 5e2 + 10;
const long long MX5 = 5e5 + 10;
const long long MX6 = 2e6 + 10;
const long long LOG = 20;
const long long INF = 8e18;
const double eps = 1e-9;
const long long MOD = 1e9 + 7;
long long power(long long a, long long b, long long md) {
  return (!b ? 1
             : (b & 1 ? a * power(a * a % md, b / 2, md) % md
                      : power(a * a % md, b / 2, md) % md));
}
long long bmm(long long a, long long b) {
  return (a % b == 0 ? b : bmm(b, a % b));
}
string base2(long long n) {
  string a = "";
  while (n >= 2) {
    a += (char)(n % 2 + '0');
    n /= 2;
  }
  a += (char)(n + '0');
  reverse((a).begin(), (a).end());
  return a;
}
long long n, m, t, PO, q, k;
long long cnt[MX5], cop[MX5], Ans[MX5];
pair<long long, long long> Merged[MX6];
long long par[MX5], SZ[MX5];
vector<pair<long long, long long> > E[MX5], W[MX5];
vector<pair<long long, pair<long long, long long> > > Edge, E1;
vector<long long> vec;
void init() {
  for (int i = 0; i <= n; i++) {
    SZ[i] = 1;
    par[i] = i;
  }
  return;
}
long long Find(long long u) {
  if (par[u] == u) {
    return u;
  }
  return Find(par[u]);
}
bool Union(long long u, long long v) {
  long long p1 = Find(u), p2 = Find(v);
  if (p1 == p2) {
    return 0;
  }
  if (SZ[p1] > SZ[p2]) {
    par[p2] = p1;
    SZ[p1] += SZ[p2];
    Merged[PO].first = p1;
    Merged[PO].second = p2;
    PO++;
  } else {
    par[p1] = p2;
    SZ[p2] += SZ[p1];
    Merged[PO].first = p2;
    Merged[PO].second = p1;
    PO++;
  }
  return 1;
}
void Undo() {
  if (PO == 0) {
    cout << "SHIT !!" << '\n';
    return;
  }
  long long u = Merged[PO - 1].first, v = Merged[PO - 1].second;
  SZ[u] -= SZ[v];
  par[v] = v;
  PO--;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  init();
  for (int i = 0; i < m; i++) {
    long long u, v, w;
    cin >> u >> v >> w;
    E[w].push_back(make_pair(u, v));
    Edge.push_back(make_pair(w, make_pair(u, v)));
  }
  cin >> q;
  while (q--) {
    cin >> k;
    for (int i = 0; i < k; i++) {
      long long a;
      cin >> a;
      a--;
      long long w = Edge[a].first;
      W[w].push_back({t, a});
    }
    t++;
  }
  for (int i = 0; i < MX5; i++) {
    if (E[i].empty()) continue;
    for (int j = 0; j < W[i].size(); j++) {
      long long pointer = j, ted = 0;
      while (pointer < W[i].size() && W[i][j].first == W[i][pointer].first)
        pointer++;
      for (int k = j; k < pointer; k++) {
        long long ind = W[i][k].second, qu = W[i][k].first;
        long long u = Edge[ind].second.first, v = Edge[ind].second.second,
                  w = Edge[ind].first;
        if (Find(u) == Find(v)) {
          Ans[qu] = 1;
        } else {
          Union(u, v);
          ted++;
        }
      }
      while (ted--) {
        Undo();
      }
      j = pointer - 1;
    }
    for (int j = 0; j < E[i].size(); j++) {
      long long u = E[i][j].first, v = E[i][j].second;
      Union(u, v);
    }
  }
  for (int i = 0; i < t; i++) {
    cout << (Ans[i] ? "NO" : "YES") << '\n';
  }
  return 0;
}
