#include <bits/stdc++.h>
struct Edge2 {
  int first, sec, weight;
  bool operator<(Edge2 other) const { return weight < other.weight; }
};
struct DisjointSet {
  std::vector<int> par;
  struct Change {
    int index, old;
  };
  std::vector<Change> history;
  DisjointSet(int number) : par(number, -1), history() {}
  void undo() {
    auto [index, old] = history.back();
    history.pop_back();
    par[index] = old;
  }

 private:
  int set(int index, int value) {
    if (par[index] == value) return value;
    history.push_back({index, par[index]});
    return par[index] = value;
  }

 public:
  int root(int node) const {
    assert(node != -1);
    return par[node] >= 0 ? root(par[node]) : node;
  }
  bool join(int first, int sec) {
    first = root(first);
    sec = root(sec);
    if (first == sec) return false;
    if (par[first] > par[sec]) std::swap(first, sec);
    if (par[first] == par[sec]) --par[first];
    set(sec, first);
    return true;
  }
};
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int numNode, numEdge;
  std::cin >> numNode >> numEdge;
  struct Group {
    struct QueryPart {
      int index;
      std::vector<std::pair<int, int>> edges;
    };
    std::vector<QueryPart> queryParts;
    std::vector<std::pair<int, int>> edges;
  };
  std::map<int, Group> groups;
  std::vector<Edge2> edges(numEdge);
  for (auto& [first, sec, weight] : edges) {
    std::cin >> first >> sec >> weight;
    --first;
    --sec;
    groups[weight].edges.push_back({first, sec});
  }
  DisjointSet set(numNode);
  int numQuery;
  std::cin >> numQuery;
  for (int queryIndex = 0; queryIndex < numQuery; ++queryIndex) {
    int number;
    std::cin >> number;
    for (int _ = 0; _ < number; ++_) {
      int edgeIndex;
      std::cin >> edgeIndex;
      --edgeIndex;
      auto const [first, sec, weight] = edges[edgeIndex];
      auto& it = groups[weight].queryParts;
      if (it.empty() or it.back().index != queryIndex) {
        it.emplace_back();
        it.back().index = queryIndex;
      }
      it.back().edges.push_back({first, sec});
    }
  }
  std::vector<char> result(numQuery, true);
  for (auto const& [_weight, group] : groups) {
    auto historyPos = set.history.size();
    for (auto const& queryPart : group.queryParts) {
      if (not result[queryPart.index]) continue;
      for (auto [first, sec] : queryPart.edges) {
        if (not set.join(first, sec)) result[queryPart.index] = false;
      }
      while (set.history.size() != historyPos) set.undo();
    }
    for (auto [first, sec] : group.edges) {
      set.join(first, sec);
    }
  }
  for (auto okay : result) std::cout << (okay ? "YES\n" : "NO\n");
}
