#include <bits/stdc++.h>
using namespace std;
class disjoint_union {
 private:
  vector<int> parent, rank;

 public:
  disjoint_union(int size);
  int find(int n);
  void unionize(int a, int b);
};
bool can_mstize(const vector<tuple<int, int, int>>& edge,
                const vector<bool>& mst_valid,
                const vector<pair<int, int>>& edge_snapshot,
                const vector<int>& subset);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int nodes, edges;
  cin >> nodes >> edges;
  vector<tuple<int, int, int>> edge(edges);
  vector<pair<int, int>> edge_weights(edges);
  vector<bool> mst_valid(edges);
  vector<pair<int, int>> edge_snapshot(edges);
  for (int i = 0; i < edges; i++) {
    cin >> get<0>(edge[i]) >> get<1>(edge[i]) >> get<2>(edge[i]);
    get<0>(edge[i])--;
    get<1>(edge[i])--;
    edge_weights[i] = make_pair(get<2>(edge[i]), i);
  }
  disjoint_union du(nodes);
  sort(edge_weights.begin(), edge_weights.end());
  for (int i = 0; i < edge_weights.size(); i++) {
    int end = i;
    while (end + 1 < edge_weights.size() &&
           edge_weights[end + 1].first == edge_weights[i].first)
      end++;
    for (int j = i; j <= end; j++) {
      int e = edge_weights[j].second;
      int a_comp = du.find(get<0>(edge[e]));
      int b_comp = du.find(get<1>(edge[e]));
      if (a_comp != b_comp) mst_valid[e] = true;
      edge_snapshot[e] = make_pair(a_comp, b_comp);
    }
    for (int j = i; j <= end; j++) {
      int e = edge_weights[j].second;
      du.unionize(get<0>(edge[e]), get<1>(edge[e]));
    }
    i = end;
  }
  int queries;
  cin >> queries;
  for (int i = 0; i < queries; i++) {
    int size;
    cin >> size;
    vector<int> subset(size);
    for (int j = 0; j < size; j++) {
      cin >> subset[j];
      subset[j]--;
    }
    cout << (can_mstize(edge, mst_valid, edge_snapshot, subset) ? "YES\n"
                                                                : "NO\n");
  }
}
disjoint_union::disjoint_union(int size) : parent(size), rank(size) {
  for (int i = 0; i < parent.size(); i++) parent[i] = i;
}
int disjoint_union::find(int n) {
  if (parent[n] == n) return n;
  return parent[n] = find(parent[n]);
}
void disjoint_union::unionize(int a, int b) {
  int a_root = find(a), b_root = find(b);
  if (a_root == b_root) return;
  if (rank[a_root] < rank[b_root])
    parent[a_root] = b_root;
  else if (rank[b_root] < rank[a_root])
    parent[b_root] = a_root;
  else {
    parent[b_root] = a_root;
    rank[a_root]++;
  }
}
int get_index(map<int, int>& index, int value) {
  if (index.find(value) != index.end()) return index[value];
  int size = index.size();
  return index[value] = size;
}
bool in_cycle(const vector<tuple<int, int, int>>& edge,
              const vector<pair<int, int>>& edge_snapshot,
              const vector<int>& subset,
              const vector<pair<int, int>>& edge_weights, int start, int end) {
  map<int, int> index;
  for (int i = start; i <= end; i++) {
    int e = edge_weights[i].second;
    int a_comp = get_index(index, edge_snapshot[e].first);
    int b_comp = get_index(index, edge_snapshot[e].second);
  }
  disjoint_union du(index.size());
  for (int i = start; i <= end; i++) {
    int e = edge_weights[i].second;
    int a_comp = get_index(index, edge_snapshot[e].first);
    int b_comp = get_index(index, edge_snapshot[e].second);
    if (du.find(a_comp) == du.find(b_comp)) return true;
    du.unionize(a_comp, b_comp);
  }
  return false;
}
bool can_mstize(const vector<tuple<int, int, int>>& edge,
                const vector<bool>& mst_valid,
                const vector<pair<int, int>>& edge_snapshot,
                const vector<int>& subset) {
  for (int i = 0; i < subset.size(); i++)
    if (!mst_valid[subset[i]]) return false;
  vector<pair<int, int>> edge_weights(subset.size());
  for (int i = 0; i < subset.size(); i++)
    edge_weights[i] = make_pair(get<2>(edge[subset[i]]), subset[i]);
  sort(edge_weights.begin(), edge_weights.end());
  for (int i = 0; i < edge_weights.size(); i++) {
    int end = i;
    while (end + 1 < edge_weights.size() &&
           edge_weights[end + 1].first == edge_weights[i].first)
      end++;
    if (in_cycle(edge, edge_snapshot, subset, edge_weights, i, end))
      return false;
    i = end;
  }
  return true;
}
