#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& t) {
  return os << '[' << t.first << ',' << t.second << ']';
}
void print_tpl_helper(ostream&, bool) {}
template <typename T, typename... Ts>
void print_tpl_helper(ostream& os, bool first, const T& v, const Ts&... vs) {
  if (!first) {
    os << ',';
  }
  os << v;
  print_tpl_helper(os, false, vs...);
}
template <typename... Ts>
ostream& print_struct(ostream& os, const char* classname, const Ts&... vs) {
  os << classname << '(';
  print_tpl_helper(os, true, vs...);
  return os << ')';
}
struct Example {
  char symbol;
  u64 val;
  friend ostream& operator<<(ostream& os, const Example& elem) {
    return print_struct(os, "Op", elem.symbol, elem.val);
  }
};
template <typename It>
void print(ostream& os, It begin, It end, u64 len, u64 limit = 30) {
  u64 count = 0;
  os << "{";
  while (begin != end && count < limit) {
    os << "(" << *begin << ")";
    count++;
    begin++;
  }
  if (begin != end) os << "... " << len << " total";
  os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const unordered_map<T1, T2>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
T read() {
  T e;
  cin >> e;
  return e;
}
void read() {}
template <typename T, typename... Ts>
void read(T& v, Ts&... ts) {
  v = read<T>();
  read(ts...);
}
template <typename T>
vector<T> readv(u64 n) {
  vector<T> v;
  for (u64 i = 0; i < n; i++) v.push_back(read<T>());
  return v;
}
template <typename T>
struct identity {
  const T& operator()(const T& t) const { return t; }
};
template <typename T>
void print(const T& t) {
  cout << t << ' ';
}
void println() { cout << '\n'; }
template <typename T>
void println(const T& t) {
  cout << t << '\n';
}
template <typename T, typename F = identity<typename T::value_type>>
void printv(const T& t, F f = F()) {
  for (const auto& e : t) print(f(e));
  println();
}
class FU {
 public:
  FU(u64 n) : ranges_(n), sets_(n) {
    for (u64 i = 0; i < sets_.size(); i++) sets_[i] = i;
  }
  void clear(u64 x) {
    sets_[x] = x;
    ranges_[x] = 0;
  }
  u64 find(u64 a) {
    assert(a < sets_.size());
    path_.clear();
    while (sets_[a] != a) {
      path_.push_back(a);
      a = sets_[a];
    }
    for (auto p : path_) sets_[p] = a;
    return a;
  }
  void un(u64 a, u64 b) {
    a = find(a);
    b = find(b);
    if (ranges_[a] > ranges_[b]) swap(a, b);
    if (ranges_[a] == ranges_[b]) ranges_[b]++;
    sets_[a] = b;
  }

 private:
  vector<u64> path_;
  vector<u64> ranges_;
  vector<u64> sets_;
};
u64 n;
vector<pair<u64, u64>> edges;
vector<vector<u64>> get_sorted_edges(vector<u64> weights) {
  vector<u64> nedges;
  for (u64 i = 0; i < edges.size(); i++) nedges.push_back(i);
  sort(nedges.begin(), nedges.end(),
       [&weights](u64 a, u64 b) { return weights[a] < weights[b]; });
  vector<vector<u64>> sedges;
  for (u64 i = 0; i < nedges.size();) {
    u64 j = i;
    vector<u64> wedges;
    while (j < nedges.size() && weights[nedges[j]] == weights[nedges[i]]) {
      wedges.push_back(nedges[j]);
      j++;
    }
    sedges.push_back(wedges);
    assert(j > i);
    i = j;
  }
  return sedges;
}
bool solve(FU& findunion, const vector<u64>& subset) {
  for (const auto& e : subset) {
    findunion.clear(edges[e].first);
    findunion.clear(edges[e].second);
  }
  for (const auto& e : subset) {
    if (findunion.find(edges[e].first) == findunion.find(edges[e].second))
      return false;
    findunion.un(edges[e].first, edges[e].second);
  }
  return true;
}
void go() {
  u64 m;
  read(n, m);
  vector<u64> weights;
  for (u64 i = 0; i < m; i++) {
    u64 a, b, c;
    read(a, b, c);
    a--;
    b--;
    edges.emplace_back(a, b);
    weights.push_back(c);
  }
  auto sorted_edges = get_sorted_edges(weights);
  FU findunion(n);
  for (const auto& gedges : sorted_edges) {
    for (const auto& e : gedges) {
      edges[e].first = findunion.find(edges[e].first);
      edges[e].second = findunion.find(edges[e].second);
    }
    for (const auto& e : gedges) {
      if (findunion.find(edges[e].first) != findunion.find(edges[e].second))
        findunion.un(edges[e].first, edges[e].second);
    }
  }
  u64 k;
  read(k);
  while (k--) {
    auto z = read<u64>();
    vector<u64> subset;
    for (u64 i = 0; i < z; i++) {
      auto e = read<u64>();
      e--;
      subset.push_back(e);
    }
    println(solve(findunion, subset) ? "YES" : "NO");
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  go();
}

### Prompt

Please create a solution in Cpp to the following problem:

For a connected undirected weighted graph G, MST (minimum spanning tree) is a subgraph of G that contains all of G's vertices, is a tree, and sum of its edges is minimum possible.

You are given a graph G. If you run a MST algorithm on graph it would give you only one MST and it causes other edges to become jealous. You are given some queries, each query contains a set of edges of graph G, and you should determine whether there is a MST containing all these edges or not.

Input

The first line contains two integers n, m (2 ≤ n, m ≤ 5·105, n - 1 ≤ m) — the number of vertices and edges in the graph and the number of queries.

The i-th of the next m lines contains three integers ui, vi, wi (ui ≠ vi, 1 ≤ wi ≤ 5·105) — the endpoints and weight of the i-th edge. There can be more than one edges between two vertices. It's guaranteed that the given graph is connected.

The next line contains a single integer q (1 ≤ q ≤ 5·105) — the number of queries.

q lines follow, the i-th of them contains the i-th query. It starts with an integer ki (1 ≤ ki ≤ n - 1) — the size of edges subset and continues with ki distinct space-separated integers from 1 to m — the indices of the edges. It is guaranteed that the sum of ki for 1 ≤ i ≤ q does not exceed 5·105.

Output

For each query you should print "YES" (without quotes) if there's a MST containing these edges and "NO" (of course without quotes again) otherwise.

Example

Input

5 7
1 2 2
1 3 2
2 3 1
2 4 1
3 4 1
3 5 2
4 5 2
4
2 3 4
3 3 4 5
2 1 7
2 1 2


Output

YES
NO
YES
NO

Note

This is the graph of sample:

<image>

Weight of minimum spanning tree on this graph is 6.

MST with edges (1, 3, 4, 6), contains all of edges from the first query, so answer on the first query is "YES".

Edges from the second query form a cycle of length 3, so there is no spanning tree including these three edges. Thus, answer is "NO".

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& t) {
  return os << '[' << t.first << ',' << t.second << ']';
}
void print_tpl_helper(ostream&, bool) {}
template <typename T, typename... Ts>
void print_tpl_helper(ostream& os, bool first, const T& v, const Ts&... vs) {
  if (!first) {
    os << ',';
  }
  os << v;
  print_tpl_helper(os, false, vs...);
}
template <typename... Ts>
ostream& print_struct(ostream& os, const char* classname, const Ts&... vs) {
  os << classname << '(';
  print_tpl_helper(os, true, vs...);
  return os << ')';
}
struct Example {
  char symbol;
  u64 val;
  friend ostream& operator<<(ostream& os, const Example& elem) {
    return print_struct(os, "Op", elem.symbol, elem.val);
  }
};
template <typename It>
void print(ostream& os, It begin, It end, u64 len, u64 limit = 30) {
  u64 count = 0;
  os << "{";
  while (begin != end && count < limit) {
    os << "(" << *begin << ")";
    count++;
    begin++;
  }
  if (begin != end) os << "... " << len << " total";
  os << "}";
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const unordered_map<T1, T2>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const unordered_set<T>& t) {
  print(os, t.begin(), t.end(), t.size());
  return os;
}
template <typename T>
T read() {
  T e;
  cin >> e;
  return e;
}
void read() {}
template <typename T, typename... Ts>
void read(T& v, Ts&... ts) {
  v = read<T>();
  read(ts...);
}
template <typename T>
vector<T> readv(u64 n) {
  vector<T> v;
  for (u64 i = 0; i < n; i++) v.push_back(read<T>());
  return v;
}
template <typename T>
struct identity {
  const T& operator()(const T& t) const { return t; }
};
template <typename T>
void print(const T& t) {
  cout << t << ' ';
}
void println() { cout << '\n'; }
template <typename T>
void println(const T& t) {
  cout << t << '\n';
}
template <typename T, typename F = identity<typename T::value_type>>
void printv(const T& t, F f = F()) {
  for (const auto& e : t) print(f(e));
  println();
}
class FU {
 public:
  FU(u64 n) : ranges_(n), sets_(n) {
    for (u64 i = 0; i < sets_.size(); i++) sets_[i] = i;
  }
  void clear(u64 x) {
    sets_[x] = x;
    ranges_[x] = 0;
  }
  u64 find(u64 a) {
    assert(a < sets_.size());
    path_.clear();
    while (sets_[a] != a) {
      path_.push_back(a);
      a = sets_[a];
    }
    for (auto p : path_) sets_[p] = a;
    return a;
  }
  void un(u64 a, u64 b) {
    a = find(a);
    b = find(b);
    if (ranges_[a] > ranges_[b]) swap(a, b);
    if (ranges_[a] == ranges_[b]) ranges_[b]++;
    sets_[a] = b;
  }

 private:
  vector<u64> path_;
  vector<u64> ranges_;
  vector<u64> sets_;
};
u64 n;
vector<pair<u64, u64>> edges;
vector<vector<u64>> get_sorted_edges(vector<u64> weights) {
  vector<u64> nedges;
  for (u64 i = 0; i < edges.size(); i++) nedges.push_back(i);
  sort(nedges.begin(), nedges.end(),
       [&weights](u64 a, u64 b) { return weights[a] < weights[b]; });
  vector<vector<u64>> sedges;
  for (u64 i = 0; i < nedges.size();) {
    u64 j = i;
    vector<u64> wedges;
    while (j < nedges.size() && weights[nedges[j]] == weights[nedges[i]]) {
      wedges.push_back(nedges[j]);
      j++;
    }
    sedges.push_back(wedges);
    assert(j > i);
    i = j;
  }
  return sedges;
}
bool solve(FU& findunion, const vector<u64>& subset) {
  for (const auto& e : subset) {
    findunion.clear(edges[e].first);
    findunion.clear(edges[e].second);
  }
  for (const auto& e : subset) {
    if (findunion.find(edges[e].first) == findunion.find(edges[e].second))
      return false;
    findunion.un(edges[e].first, edges[e].second);
  }
  return true;
}
void go() {
  u64 m;
  read(n, m);
  vector<u64> weights;
  for (u64 i = 0; i < m; i++) {
    u64 a, b, c;
    read(a, b, c);
    a--;
    b--;
    edges.emplace_back(a, b);
    weights.push_back(c);
  }
  auto sorted_edges = get_sorted_edges(weights);
  FU findunion(n);
  for (const auto& gedges : sorted_edges) {
    for (const auto& e : gedges) {
      edges[e].first = findunion.find(edges[e].first);
      edges[e].second = findunion.find(edges[e].second);
    }
    for (const auto& e : gedges) {
      if (findunion.find(edges[e].first) != findunion.find(edges[e].second))
        findunion.un(edges[e].first, edges[e].second);
    }
  }
  u64 k;
  read(k);
  while (k--) {
    auto z = read<u64>();
    vector<u64> subset;
    for (u64 i = 0; i < z; i++) {
      auto e = read<u64>();
      e--;
      subset.push_back(e);
    }
    println(solve(findunion, subset) ? "YES" : "NO");
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  go();
}

```