#include <bits/stdc++.h>
using namespace std;
int n, m, i, Q, j, k, kk, x, w, TT, b[555555], X[555555], Y[555555], Z[555555],
    F[555555], FF[555555], gg[555555], tim[555555];
vector<pair<int, int> > V[555555];
bool cmp(int x, int y) { return Z[x] < Z[y]; }
int gf(int x) { return F[x] == x ? x : F[x] = gf(F[x]); }
int gff(int x) {
  if (tim[x] != TT) tim[x] = TT, FF[x] = F[x];
  return FF[x] == x ? x : FF[x] = gff(FF[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &X[i], &Y[i], &Z[i]), b[i] = i;
  sort(b + 1, b + m + 1, cmp);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++)
      scanf("%d", &x), V[Z[x]].push_back(make_pair(i, x));
  }
  for (int i = 1; i <= n; i++) F[i] = i;
  w = 1;
  for (int i = 1; i <= 500001; i++) {
    sort(V[i].begin(), V[i].end());
    for (j = k = 0; j < V[i].size(); j = k) {
      TT++;
      for (kk = k; k < V[i].size() && V[i][j].first == V[i][k].first; k++) {
        x = V[i][k].second;
        FF[X[x]] = gf(X[x]);
        FF[Y[x]] = gf(Y[x]);
        tim[X[x]] = TT;
        tim[Y[x]] = TT;
      }
      for (k = kk; k < V[i].size() && V[i][j].first == V[i][k].first; k++) {
        x = V[i][k].second;
        if (gff(X[x]) == gff(Y[x])) gg[V[i][j].first] = 1;
        FF[gff(X[x])] = gff(Y[x]);
      }
    }
    for (; w <= m && Z[b[w]] == i; w++) F[gf(X[b[w]])] = gf(Y[b[w]]);
  }
  for (int i = 1; i <= Q; i++) puts(gg[i] ? "NO" : "YES");
}

### Prompt

Develop a solution in cpp to the problem described below:

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;
int n, m, i, Q, j, k, kk, x, w, TT, b[555555], X[555555], Y[555555], Z[555555],
    F[555555], FF[555555], gg[555555], tim[555555];
vector<pair<int, int> > V[555555];
bool cmp(int x, int y) { return Z[x] < Z[y]; }
int gf(int x) { return F[x] == x ? x : F[x] = gf(F[x]); }
int gff(int x) {
  if (tim[x] != TT) tim[x] = TT, FF[x] = F[x];
  return FF[x] == x ? x : FF[x] = gff(FF[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d%d", &X[i], &Y[i], &Z[i]), b[i] = i;
  sort(b + 1, b + m + 1, cmp);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d", &k);
    for (int j = 1; j <= k; j++)
      scanf("%d", &x), V[Z[x]].push_back(make_pair(i, x));
  }
  for (int i = 1; i <= n; i++) F[i] = i;
  w = 1;
  for (int i = 1; i <= 500001; i++) {
    sort(V[i].begin(), V[i].end());
    for (j = k = 0; j < V[i].size(); j = k) {
      TT++;
      for (kk = k; k < V[i].size() && V[i][j].first == V[i][k].first; k++) {
        x = V[i][k].second;
        FF[X[x]] = gf(X[x]);
        FF[Y[x]] = gf(Y[x]);
        tim[X[x]] = TT;
        tim[Y[x]] = TT;
      }
      for (k = kk; k < V[i].size() && V[i][j].first == V[i][k].first; k++) {
        x = V[i][k].second;
        if (gff(X[x]) == gff(Y[x])) gg[V[i][j].first] = 1;
        FF[gff(X[x])] = gff(Y[x]);
      }
    }
    for (; w <= m && Z[b[w]] == i; w++) F[gf(X[b[w]])] = gf(Y[b[w]]);
  }
  for (int i = 1; i <= Q; i++) puts(gg[i] ? "NO" : "YES");
}

```