#include <bits/stdc++.h>
using namespace std;
struct edge {
  int a, b, w;
  edge() {}
  edge(int a, int b, int w) {
    this->a = a;
    this->b = b;
    this->w = w;
  }
};
const int N = 500001;
int n, m, q, p[N], r[N];
vector<edge> e;
map<int, vector<int> > v[N];
vector<int> all[N];
vector<int> c;
vector<pair<int, int> > p_updates, r_updates;
bool ans[N];
void join(int a, int b) {
  if (r[a] == r[b]) {
    p_updates.push_back(make_pair(a, p[a]));
    r_updates.push_back(make_pair(b, r[b]));
    p[a] = b;
    r[b]++;
  } else {
    if (r[a] > r[b]) swap(a, b);
    p_updates.push_back(make_pair(a, p[a]));
    r_updates.push_back(make_pair(a, r[a]));
    p[a] = b;
  }
}
void ctrl_z() {
  p[p_updates.back().first] = p_updates.back().second;
  p_updates.pop_back();
  r[r_updates.back().first] = r_updates.back().second;
  r_updates.pop_back();
}
int find(int u) {
  if (u == p[u]) return u;
  return find(p[u]);
}
int main() {
  scanf("%d%d", &n, &m);
  e.resize(m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d%d", &e[i].a, &e[i].b, &e[i].w);
    c.push_back(e[i].w);
    all[e[i].w].push_back(i);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int k, x;
    scanf("%d", &k);
    for (int j = 0; j < k; j++) {
      scanf("%d", &x);
      x--;
      v[e[x].w][i].push_back(x);
    }
  }
  sort(c.begin(), c.end());
  c.resize(unique(c.begin(), c.end()) - c.begin());
  memset(ans, 1, sizeof ans);
  for (int i = 0; i < n; i++) {
    p[i] = i;
    r[i] = 1;
  }
  for (int i = 0, a, b, last; i < c.size(); i++) {
    for (map<int, vector<int> >::iterator j = v[c[i]].begin();
         j != v[c[i]].end(); j++) {
      last = p_updates.size();
      for (int k = 0; k < j->second.size(); k++) {
        a = e[j->second[k]].a, b = e[j->second[k]].b;
        a = find(a), b = find(b);
        if (a == b)
          ans[j->first] = 0;
        else
          join(a, b);
      }
      while (p_updates.size() != last) ctrl_z();
    }
    for (int j = 0, a, b; j < all[c[i]].size(); j++) {
      a = e[all[c[i]][j]].a, b = e[all[c[i]][j]].b;
      a = find(a), b = find(b);
      if (a != b) join(a, b);
    }
  }
  for (int i = 0; i < q; i++) puts(ans[i] ? "YES" : "NO");
  return 0;
}
