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".
#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1;
struct union_find {
  int par[N];
  int sz[N];
  vector<array<int, 2>> stk;
  void init(int n) {
    iota(par, par + n, 0);
    fill(sz, sz + n, 1);
  }
  int find(int u) {
    if (par[u] != u) {
      return find(par[u]);
    }
    return par[u];
  }
  bool unite(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (sz[u] > sz[v]) {
      swap(u, v);
    }
    par[u] = v;
    sz[v] += sz[u];
    stk.push_back({u, v});
    return true;
  }
  void roll_back() {
    auto [u, v] = stk.back();
    stk.pop_back();
    sz[v] -= sz[u];
    par[u] = u;
  }
} dsu;
bool ans[N];
int u[N];
int v[N];
int w[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> u[i] >> v[i] >> w[i];
    --u[i], --v[i];
  }
  int q;
  cin >> q;
  fill(ans, ans + q, true);
  vector<array<int, 3>> events;
  for (int i = 0; i < q; ++i) {
    int k;
    cin >> k;
    while (k--) {
      int e;
      cin >> e;
      events.push_back({w[e], i, e});
    }
  }
  for (int i = 1; i <= m; ++i) {
    events.push_back({w[i], q, i});
  }
  sort(events.begin(), events.end());
  int pre = 0;
  int cnt = 0;
  dsu.init(n);
  for (auto [c, i, e] : events) {
    if (i != pre && pre != q) {
      while (cnt > 0) {
        dsu.roll_back();
        --cnt;
      }
    }
    bool res = dsu.unite(u[e], v[e]);
    if (i != q) {
      ans[i] &= res;
      cnt += res;
    }
    pre = i;
  }
  for (int i = 0; i < q; ++i) {
    cout << (ans[i] ? "YES" : "NO") << "\n";
  }
}
