#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int u;
  int v;
  Edge() {}
  Edge(int u, int v) : u(u), v(v) {}
};
struct WeightedEdge : Edge {
  int w;
};
struct EdgeGroup {
  int q;
  vector<Edge> edges;
  EdgeGroup() { q = -1; }
  EdgeGroup(int q) : q(q) {}
};
const int MAX_M = 500005;
const int MAX_W = 500005;
const int MAX_N = 500005;
const int MAX_Q = 500005;
WeightedEdge raw_edge[MAX_M];
int vertex_set[MAX_N];
int cycle_set[MAX_N];
vector<Edge> edge[MAX_W];
vector<EdgeGroup> edge_group[MAX_W];
bool ans[MAX_Q];
int get_canonical(int disjoint_set[], int v) {
  if (disjoint_set[v] == v) return v;
  return disjoint_set[v] = get_canonical(disjoint_set, disjoint_set[v]);
}
bool join(int disjoint_set[], int u, int v) {
  u = get_canonical(disjoint_set, u);
  v = get_canonical(disjoint_set, v);
  if (u == v) {
    return false;
  }
  disjoint_set[v] = u;
  return true;
}
bool check(const vector<Edge> &edges) {
  vector<Edge> canonic_edges;
  for (auto e : edges) {
    int v = get_canonical(vertex_set, e.v);
    int u = get_canonical(vertex_set, e.u);
    cycle_set[v] = v;
    cycle_set[u] = u;
    canonic_edges.emplace_back(u, v);
  }
  for (auto e : canonic_edges) {
    if (!join(cycle_set, e.v, e.u)) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) {
    vertex_set[i] = i;
  }
  for (int i = 1; i <= m; ++i) {
    cin >> raw_edge[i].u >> raw_edge[i].v >> raw_edge[i].w;
    edge[raw_edge[i].w].emplace_back(raw_edge[i].v, raw_edge[i].u);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    ans[i] = true;
    int k;
    cin >> k;
    for (int j = 0; j < k; ++j) {
      int edge_id;
      cin >> edge_id;
      int w = raw_edge[edge_id].w;
      if (edge_group[w].empty() || edge_group[w].back().q != i) {
        edge_group[w].emplace_back(i);
      }
      edge_group[w].back().edges.push_back(raw_edge[edge_id]);
    }
  }
  for (int w = 1; w < MAX_W; ++w) {
    for (auto group : edge_group[w]) {
      ans[group.q] &= check(group.edges);
    }
    for (auto e : edge[w]) {
      join(vertex_set, e.v, e.u);
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << (ans[i] ? "YES" : "NO") << "\n";
  }
  return 0;
}
