#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
  if (!b) return 1;
  if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
  return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 5e5 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
struct DSU {
  int par[MAXN];
  DSU() { fill(par, par + MAXN, -1); }
  int Find(int u) { return (par[u] == -1 ? u : par[u] = Find(par[u])); }
  bool Union(int u, int v) {
    int pu = Find(u), pv = Find(v);
    if (pu == pv) return false;
    par[pv] = pu;
    return true;
  }
};
int n, m, q, ans[MAXN];
vector<pair<int, int>> wq[MAXN], wedg[MAXN];
vector<pair<int, pair<int, int>>> E;
DSU dsu[2];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    E.push_back({w, {u, v}});
    wedg[w].emplace_back(u, v);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int k, e;
    cin >> k;
    for (int j = 0; j < k; j++) {
      cin >> e;
      wq[E[e - 1].first].emplace_back(i, e - 1);
    }
  }
  for (int i = 0; i < MAXN; i++) {
    for (int j = 0; j < wq[i].size(); j++) {
      int k = j;
      for (; k < wq[i].size() && wq[i][j].first == wq[i][k].first; k++) {
      }
      for (int l = j; l < k; l++) {
        int u = E[wq[i][l].second].second.first,
            v = E[wq[i][l].second].second.second;
        int pu = dsu[0].Find(u), pv = dsu[0].Find(v);
        dsu[1].par[u] = pu;
        dsu[1].par[v] = pv;
        dsu[1].par[pu] = dsu[1].par[pv] = -1;
      }
      for (int l = j; l < k; l++) {
        int u = E[wq[i][l].second].second.first,
            v = E[wq[i][l].second].second.second;
        if (!dsu[1].Union(u, v)) ans[wq[i][j].first] = 1;
      }
      j = k - 1;
    }
    for (pair<int, int> e : wedg[i]) {
      dsu[0].Union(e.first, e.second);
    }
  }
  for (int i = 0; i < q; i++) {
    cout << (ans[i] == 1 ? "NO" : "YES") << '\n';
  }
  return 0;
}
