#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const long long mod = 1e9 + 7;
const int maxn = 1e6 + 5;
struct Edge {
  int u, v, w, i;
};
int n, m;
Edge edge[maxn];
map<int, vector<int>> mp;
int par[maxn];
bool mst[maxn];
pair<int, int> pa[maxn];
int find(int u) {
  if (par[u] == u) return u;
  return par[u] = find(par[u]);
}
bool check(vector<int> l) {
  for (int ei : l) {
    int a = pa[ei].first;
    int b = pa[ei].second;
    par[a] = a;
    par[b] = b;
  }
  for (int ei : l) {
    int a = find(pa[ei].first);
    int b = find(pa[ei].second);
    if (a == b) return false;
    par[a] = b;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge[i] = {u, v, w, i};
    mp[w].push_back(i);
    mst[i] = true;
  }
  for (int i = 1; i <= n; i++) {
    par[i] = i;
  }
  for (auto p : mp) {
    for (int ei : p.second) {
      int u = edge[ei].u;
      int v = edge[ei].v;
      if (find(u) == find(v)) {
        mst[ei] = false;
      } else {
        pa[ei] = {find(u), find(v)};
      }
    }
    for (int ei : p.second) {
      int u = find(edge[ei].u);
      int v = find(edge[ei].v);
      par[u] = v;
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    bool ok = true;
    map<int, vector<int>> ee;
    for (int i = 0; i < k; i++) {
      int id;
      cin >> id;
      --id;
      auto &ed = edge[id];
      if (!mst[id]) ok = false;
      ee[ed.w].push_back(id);
    }
    if (ok) {
      for (auto p : ee) {
        if (!check(p.second)) ok = false;
      }
    }
    if (ok) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
