#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 7, INF = 1e9 + 7;
int n, m, cnt = 0, q, fa[MAXN], inv[MAXN] = {}, top = 0, cur = 0;
int stk[MAXN][4];
pair<int, pair<int, int> > e[MAXN], que[MAXN], s[MAXN];
int root(int u) {
  if (fa[u] < 0) return u;
  return root(fa[u]);
}
void join(int u, int v) {
  if (fa[u] < fa[v]) swap(u, v);
  stk[++top][0] = u, stk[top][1] = fa[u], stk[top][2] = v, stk[top][3] = fa[v];
  fa[v] += fa[u], fa[u] = v;
}
void undo(int len) {
  while (len--)
    fa[stk[top][0]] = stk[top][1], fa[stk[top][2]] = stk[top][3], --top;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) fa[i] = -1;
  for (int i = 1; i <= m; ++i)
    cin >> e[i].second.first >> e[i].second.second >> e[i].first, s[i] = e[i];
  sort(e + 1, e + 1 + m);
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int sz;
    cin >> sz;
    while (sz--) {
      int u;
      cin >> u, que[++cnt] = {s[u].first, {i, u}};
    }
  }
  sort(que + 1, que + 1 + cnt);
  que[0].first = -1;
  int now = 1;
  for (int i = 1; i <= m; ++i) {
    while (que[now].first == e[i].first && now <= cnt) {
      if (que[now - 1].first == que[now].first &&
          que[now - 1].second.first != que[now].second.first)
        undo(cur), cur = 0;
      int u = root(s[que[now].second.second].second.first),
          v = root(s[que[now].second.second].second.second);
      if (u == v)
        inv[que[now].second.first] = 1;
      else
        ++cur, join(u, v);
      ++now;
    }
    undo(cur), cur = 0;
    int u = root(e[i].second.first), v = root(e[i].second.second);
    if (u != v) join(u, v);
  }
  for (int i = 1; i <= q; ++i) cout << (inv[i] ? "NO" : "YES") << '\n';
}
