#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 100;
int n, m, from[MAXN], to[MAXN], a[MAXN], b[MAXN], w[MAXN], par[MAXN];
pair<int, int> edge[MAXN];
vector<int> adj[MAXN];
bool mark[MAXN];
bool dfs(int u, int par = -1) {
  mark[u] = 1;
  for (auto v : adj[u]) {
    if (!mark[v]) {
      if (dfs(v, u)) return true;
    } else if (v != par)
      return true;
  }
  return false;
}
int root(int x) { return (par[x] == x ? x : par[x] = root(par[x])); }
void merge(int x, int y) {
  x = root(x), y = root(y);
  if (x == y) return;
  par[x] = y;
}
int main() {
  iota(par, par + MAXN, 0);
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d %d ", &from[i], &to[i], &w[i]);
    from[i]--, to[i]--;
    edge[i].first = w[i];
    edge[i].second = i;
  }
  sort(edge, edge + m);
  for (int i = 0; i < m;) {
    int j = i;
    while (j < m && edge[i].first == edge[j].first) j++;
    for (int ind = i; ind < j; ind++) {
      int id = edge[ind].second;
      a[id] = root(from[id]);
      b[id] = root(to[id]);
    }
    for (int ind = i; ind < j; ind++) {
      int id = edge[ind].second;
      merge(from[id], to[id]);
    }
    i = j;
  }
  int q;
  scanf("%d ", &q);
  while (q--) {
    int k;
    scanf("%d ", &k);
    vector<pair<int, int>> Q;
    while (k--) {
      int x;
      scanf("%d", &x);
      x--;
      Q.push_back({w[x], x});
    }
    bool bad = 0;
    sort(Q.begin(), Q.end());
    for (int i = 0; i < Q.size();) {
      int j = i;
      vector<int> node;
      while (j < Q.size() && Q[i].first == Q[j].first) j++;
      for (int ind = i; ind < j; ind++) {
        int id = Q[ind].second;
        if (!mark[a[id]]) node.push_back(a[id]);
        if (!mark[b[id]]) node.push_back(b[id]);
        mark[a[id]] = mark[b[id]] = 1;
        adj[a[id]].push_back(b[id]);
        adj[b[id]].push_back(a[id]);
      }
      for (auto x : node) mark[x] = 0;
      for (auto x : node)
        if (!mark[x]) bad |= dfs(x);
      for (auto x : node) {
        adj[x].clear();
        mark[x] = 0;
      }
      i = j;
    }
    if (bad)
      printf("NO\n");
    else
      printf("YES\n");
  }
}
